Forum Moderators: coopster
I want to build a Registry object for my application, holding resources for the rest of the script such as a database connection, a custom session instance, etc etc. The Registry holds an array of references to these objects, and initialises them.
If each of those 'registerable' objects needs to have a setUp and tearDown method for the Registry to call (setUp would start the session, connect to the database etc, while tearDown would end the session, close the connect etc..) what's the best way to implement this?
An interface 'Registerable' seems to make more sense to me, even though I'm using PHP4 and will have to remember to make all the classes include those methods, although the same can be achieved by having all the classes extend a Registerable class, so over-riding the setUp and tearDown methods.
What's best?
Cheers,
Alex ...
Personally I would go the PHP 4 "interface" route, aka duck typing. Then your registry clients are free to inherit from whatever makes sense for them. You might use method_exists() in your registry code as a guard against an incomplete implementation.