[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    Re: [PHP] OOP, Classes, Sharing Code
From:       217.224.224.195
Date:       2004-06-28 19:40:57
Message-ID: 20040628193949.73090.qmail () pb1 ! pair ! com
[Download RAW message or body]

"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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic