WHAT'S HOT
Prev | Current Page 374 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

To prevent
use of the new keyword, the constructor is private (#2) and so the only way to create an instance of this class is
to call the static function getInstance() (#3). getInstance() is static as we don??™t have an instance of the class
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 59
when we call it; it returns an instance to us. Within getInstance() we only instantiate the class once (#4),
otherwise we just return the previously created instance (#5).
The net result is that the code to access the front controller is:
$frontController = Zend_Controller_Front::getInstance();
This code will work wherever it is required and will create a front controller for us if we don??™t have one,
otherwise, it returns a reference to the one that has already be created. Whilst the Singleton is easy to
implement, there is a rather large caveat with it: it??™s a global variable by the back door. As the Singleton has a
static function that returns a reference to the object, it can be called anywhere and so if used unwisely can
introduce coupling between disparate sections of a program.
Coupling
Coupling is the term used when two sections of code are linked in some way. More coupling makes it
harder to track down bugs there are more places where the code could have been changed from.


Pages:
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
motoryzacja szkoła narciarska wyrejestrowanie samochodu legnica obciążniki Wczasy nad morzem