Design Patern: It a formal way of documenting a solution to a problem.
Zend Famework mainly use following Patterns.
Singleton Pattern: It is a design pattern that restricts the instantiation of a class to one object.
Example:
class Database {
private static $_singleton;
private $_connection;
private function __construct($host,$user,$pass){
$this->_connection = mysql_connect($host,$user,$pass);
}
public static function getInstance(){
if (is_null (self::$_singleton)) {
self::$_singleton = new Database();
}
return self::$_singleton;
}
}
$db = Database::getInstance();
Factory Pattern: In this Pattern we can create an instance of any of one class in-directly from an static function of another class.
example
$db = Zend_Db::factory( ...options... );
No comments:
Post a Comment
Please add comments only related to zend framework certification.