Re: OOP, Classes, Sharing Code

From: Date: Mon, 28 Jun 2004 19:40:57 +0000
Subject: Re: OOP, Classes, Sharing Code
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-189175@lists.php.net to get a copy of this message
"Joel Kitching" <linolium@gmail.com> wrote in message news:a61df4040406281146d9ad62e@mail.gmail.com... > On Mon, 28 Jun 2004 13:41:19 -0500, Jay Blanchard > <jay.blanchard@niicommunications.com> wrote: > > If you are going to duplicate code why not just create a generic class > > with the code that would be duplicated and then extend the class as > > required? > > > > What generic class name would be appropriate in this case? I just > can't see how I would link the two together. Also, they would have to > use fairly generic variables names if I were to do this. Like using > the variable $items for the array of classes of either albums or > photos. > > Or maybe this is exactly what OOP is about and I'm just starting to get it. Hi Joel, from what you wrote it seems that only the type of display is similar in both classes. I don't think this is enough to extend them from the same base class because the class properties and update/insert/load methods will be different in each. You have more of a 'is part of' relationship here. So I'd suggest something like this (simplified): class Portfolio { var $portfolioID; var $albums = array(); } class Album { var $albumID; var $portfolioID; var $photos = array(); } class Photo { var $photoID; var $albumID; var $name; } Just my 2c. Regards, Torsten Roehr

« previous php.general (#189175) next »