Re: Subclassing versus referencing

From: Date: Wed, 05 Jan 2005 08:50:39 +0000
Subject: Re: Subclassing versus referencing
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16634@lists.php.net to get a copy of this message
On Wed, 5 Jan 2005 00:38:08 -0800, Ken Restivo <ken@restivo.org> wrote: > I'm sorry if this is a basic OOP question, but I've held off against OOP for the last > 10 years and finally I've given in. So far, I like. It's made my life a *lot* easier and > my code a lot cleaner. > > I've built an object for the main operations and state of my application. And I've > included a reference to the DBDO in it. But after doing it this way for a few weeks, my code is > riddled with $donation->obj->fieldname and $user->obj->joinAdd($donation->obj) and > other such ugliness. > > Is there any general rule as to whether and when I should subclass? I was mainly worried about > collisions-- since the bare fieldnames are vars in DBDO-- but I've already taken the FB > approach on some vars, and added them to the DBDO as $kr_thing, and I suppose I could just keep > doing that. > IMHO subclassing is way overused for some things. If your main operations class is dealing *only* with DBDO stuff (just extended to suit your needs) then by all means extend the DO. But if it's for other stuff too extending is not the correct way to do. If you class just needs access to the DO for things it's better to have it as a member. Think of it this way. A subclass is a more specific version of something, but it is still that one thing. A car is a subclass of automobile. Whereas a processor is used by a computer but a computer is not a subclass of processor. -- Justin Patrin

« previous php.pear.general (#16634) next »