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

List:       php-general
Subject:    [PHP] OOP, Classes, Sharing Code
From:       Joel Kitching <linolium () gmail ! com>
Date:       2004-06-28 18:32:52
Message-ID: a61df40404062811324455beb5 () mail ! gmail ! com
[Download RAW message or body]

I'm kind of new to OOP, so bear with me here...

I have a portfolio which contains albums.  These albums contain
photos.  So it would be natural to declare the classes:

Portfolio
Album
Photo

It seems to me that none of these classes have the "is a"
relationship, and therefore can not be "extended" from each other. 
The reason I wish to do this, is because listing albums and listing
photos use almost exactly the same code.

i.e.

// The constructor would automatically fill in the album's variables
from the database.
$album = new Album($album_id);
// This would print out the HTML for the list of photos.
$album->list_photos();

... or the same thing with "Portfolio," which would list the albums. 
The only thing that's different is the links to which the anchors are
pointing, and the content.  (Thumbnails.)

So my question is, should I just duplicate the code in each class
(Portfolio and Album), or is there a better way of organizing all of
this?

-- 
Joel Kitching
http://midgardmanga.keenspace.com/

-- 
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