Practical PHP Patterns: Registry

 Practical PHP Patterns: Registry

via PHP Zone – Community for PHP users and developers by piccoloprincipe on 9/22/10


Fowler’s definition for the Registry pattern is this one: A well known object that other ones can use to find related objects or service.This vague definition leaves open the possibility of abuse.ImplementationThe idea of a Registry is simple: providing a dynamic possibility for discovering collaborator objects, so that we not hardcode static calls to global objects like Singletons in each of…

Practical PHP Patterns: Layer Supertype

Practical PHP Patterns: Layer Supertype

via dzone.com: latest front page by piccoloprincipe on 9/21/10


Duplicated code must be kept synchronized in all its copies, and distracts whoever reads a sourcefile from the peculiarity of a class. One of the simplest, and to a certain extent effective, solution to this issue is to introduce a Layer Supertype to avoid duplication, and move all the shared code in it. Then, having the Layer Supertype subclassed by the various classes to inherit the common members, which remain defined only one time in the Layer Supertype itself. But introducing a base class isn’t always a nice solution.