Tags

,

 
interface DataBaseManager{
	public function connect();
	public function shutdown();
}

class DatabaseCommon{
	public function common_function_call(){
		print "Function common to mySql and Oracle ...";
	}
}

class mySql extends DatabaseCommon implements DataBaseManager{
	public function connect(){
		print "Connection mySql is establish ...";
	}

	public function shutdown(){
		print "Connection to mySql is destablish";
	}
}

class myOracle extends DatabaseCommon implements DataBaseManager{
	public function connect(){
		print "Connection Oracle is establish ...";
	}

	public function shutdown(){
		print "Connection to Oracle is destablish";
	}
}

class DatabaseFactory{
	public static function initialize_to( $class ){
		if(class_exists($class)) return new $class(); die ("Class Not Found $id");
	}
}


/* much better approach As you can see you can separate common functionality in another class DatabaseCommon. 
This help you to aviod changing both mySQl and Oracle class and interface class when want add more functions.*/

$mydb = DatabaseFactory::initialize_to('myOracle');
$mydb->connect();
$mydb->common_function_call();
$mydb->shutdown();

 
Advertisements