NYCPHP Meetup

NYPHP.org

[nycphp-talk] Multitons and Late Static Binding

paul at devonianfarm.com paul at devonianfarm.com
Fri Jul 25 12:22:27 EDT 2008


I've been thinking a lot about the weaknesses of static inheritance and polymorphism in most of the languages that people use.  Often we need to write really complicated code to handle initialization of systems.

In PHP,  on the other hand,  there are really good tools like dynamic constructors

$obj=new $SelectedObject($param);

and PHP 5.3 introduces late static binding.  I've been wondering if late static binding could be used to implement a Singleton or Multiton base class that other classes could inherit from.  See the following article for a typical Multiton implementation in a static language:

http://gen5.info/q/2008/07/25/the-multiton-design-pattern/

In the article I suggest that LSB could be used to do it better in PHP,  but I haven't figured out exactly how.  Any ideas?

P.S.  I think that the memory disadvantages of multitons would be less severe in PHP than they would be in other environments because of the short-lived nature of the PHP process.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080725/5ab27314/attachment.html>


More information about the talk mailing list