Factory Pattern implementation in PHP5

Factory Pattern implementation in PHP5

Factory Pattern
The factory pattern is a class that contains the methods which create objects at run time.

Implementation
Following code implemented factory pattern:

class DB{
public static function getDB($className){
$className = $type.”_”.”db”;
return new $className;
}
}

$db = DB::getDB(’MySQL’);

- The above code is creating object for which database class we need to use. For example If we change argument in MYSQL to something. Then object for that class will be created.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.