Re: Properly handling multiple constructors.
| From: | Robert Cummings | Date: | Wed, 24 Mar 2010 16:10:40 +0000 |
| Subject: | Re: Properly handling multiple constructors. | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-303332@lists.php.net to get a copy of this message | ||
Peter Lind wrote:
On 24 March 2010 16:48, Robert Cummings <robert@interjinn.com> wrote:Well that clarifies a whole lot in my mind. Although I do prefer my particular take on it, yours is obviously quite clean also :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHPBut now Dalmation_construct1 isn't related Dog_construct1. This seems problematic from a design perspective unless I'm missing something in your proposal. As for abusing class semantics ... I don't seeit. Using separate classes for different things is what OOP is about. If your constructor is trying to do 15 different things you're designing it wrong - methods shouldn't have to rely upon massive switches or the equivalent done using foreach loops and arrays.Sorry, switches, foreach, and isset are not equivalent. My approach is O( lg n ). Foreach and switches are O( n ) to find a candidate. Additionally, my constructor does 1 thing, it delegates to the appropriate constructor which does one thing also... builds the object according to intent.