OOP, Classes, Sharing Code

From: Date: Mon, 28 Jun 2004 18:32:52 +0000
Subject: OOP, Classes, Sharing Code
Groups: php.general 
Request: Send a blank email to php-general+get-189169@lists.php.net to get a copy of this message
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/

« previous php.general (#189169) next »