Design Patterns
Posted: Mon Jun 14, 2010 11:06 am
My previous thread started this discussion, but having refined the issue, I figured it warranted a new thread.
I'm having difficulty coming up with a logical and functional class hierarchy for a system, and I was wondering if someone could point me towards some resources where I could find more information, or provide some insight on how I could develop this.
I was interested in creating a system where I have a single Factory/Supervisor class, responsible for designating object instantiation of Widgets, as well as controlling global parameters that affect all Widget objects it instantiates.
The design restrictions/conditions I was trying to adhere to would be:
- The Factory class can not be instantiated and it's properties/methods are static. If a design concept has it functioning as an instantiated singleton, that would work fine as well.
- The Factory and only the factory needs to be responsible for global parameters (via Factory::setParam($args) or Factory::importParams($args), etc.) whereas the Widgets need only read the parameters (via Factory::getParam($args);).
- The Widgets (say 3 or more different types) cannot be explicitly instantiated outside of the creation methods of the Factory. (Example: $widget = Factory::createWidget($args); instead of $widget = new Widget($args);)
- The different Widgets would extend a BasicWidget to inherit general functionality.
My problem with this design is that I don't want to have:
- The Widgets inheriting Factory specific methods/properties such as setParams() or createWidget().
- The Widget's __construct($args) method making use of debug_backtrace() or another process intensive function to determine the calling method/class for instantiation restriction. Whatever keeps it running fastest.
My attempts thus far result in either of the "don't want" cases. It seems to me there must be an approach that satisfies these conditions. I posted something regarding this before, but I've refined the problem now, and hopefully someone can point me in the right direction.
I'm having difficulty coming up with a logical and functional class hierarchy for a system, and I was wondering if someone could point me towards some resources where I could find more information, or provide some insight on how I could develop this.
I was interested in creating a system where I have a single Factory/Supervisor class, responsible for designating object instantiation of Widgets, as well as controlling global parameters that affect all Widget objects it instantiates.
The design restrictions/conditions I was trying to adhere to would be:
- The Factory class can not be instantiated and it's properties/methods are static. If a design concept has it functioning as an instantiated singleton, that would work fine as well.
- The Factory and only the factory needs to be responsible for global parameters (via Factory::setParam($args) or Factory::importParams($args), etc.) whereas the Widgets need only read the parameters (via Factory::getParam($args);).
- The Widgets (say 3 or more different types) cannot be explicitly instantiated outside of the creation methods of the Factory. (Example: $widget = Factory::createWidget($args); instead of $widget = new Widget($args);)
- The different Widgets would extend a BasicWidget to inherit general functionality.
My problem with this design is that I don't want to have:
- The Widgets inheriting Factory specific methods/properties such as setParams() or createWidget().
- The Widget's __construct($args) method making use of debug_backtrace() or another process intensive function to determine the calling method/class for instantiation restriction. Whatever keeps it running fastest.
My attempts thus far result in either of the "don't want" cases. It seems to me there must be an approach that satisfies these conditions. I posted something regarding this before, but I've refined the problem now, and hopefully someone can point me in the right direction.