Re: Classes - Dumb question
| From: | Stut | Date: | Fri, 12 Oct 2007 13:44:50 +0000 |
| Subject: | Re: Classes - Dumb question | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263143@lists.php.net to get a copy of this message | ||
tedd wrote:
function customer($whatWas, $customertype, $whatAdditional) { /* do "what was" (i.e., common to all) */ /* then do what's additional unique to type */ switch(1)You can limit the need to add more code like so... function customer($whatWas, $customertype, $whatAdditional) {{ case $customertype =='Commercial': commercialCustomer($whatAdditional); break;.. and so on } function commercialCustomer($whatAdditional) { /* *only code unique to commercial customers*/} function militaryCustomer($whatAdditional) { /* *only code unique to military customers */ } In either case, I still have to write more code to accommodate scaling. And, if I have more customer types, then it's a simple matter to add more customer functions and addition case statements to the initial customer function. I don't see the benefit in using a class. At this point, it just looks like a different way of doing things.
/* do "what was" (i.e., common to all) */
/* then do what's additional unique to type */
$func = strtolower($customertype).'Customer';
$func($whatAdditional);
}
You could do (and I have done) something similar with classes.
For me the biggest benefit of using OOP is __autoload(). It makes life so much easier.
-Stut
--
http://stut.net/