From php-general Tue Jun 29 07:28:22 2004 From: Gabriel Birke Date: Tue, 29 Jun 2004 07:28:22 +0000 To: php-general Subject: Re: [PHP] OOP, Classes, Sharing Code Message-Id: X-MARC-Message: https://marc.info/?l=php-general&m=108849410701341 Hello! Another option would be to have a generic "List" class that displays items in a list. Both your Album and Photo class should implement a method like "getNextItem" or the PHP5-native iterator methods so the List class can iterate over a class assigned to it without knowing what it is. If the properties of Album and Photo are too different to generate a list, you could make a generic list class and subclass it for Album and Photo. If you want to know more about OOP, I recommend this book: http://www.amazon.com/exec/obidos/tg/detail/-/0201715945/ qid=1088493890/sr=8-1/ref=sr_8_xs_ap_i1_xgl14/102-6243709-1202536? v=glance&s=books&n=507846 It helped me a great deal understanding how to "think" object oriented. A third option would be to use the Smarty templating system. With templates you would only have to write a small portion of HTML code for each list. With best regards Gabriel Birke -- KONTOR4_Neue Medien Plathnerstraße 5 30175 Hannover Fax: +49 51184 48 98 99 mailto:birke@kontor4.de http://www.kontor4.de Am 28.06.2004 um 20:32 schrieb Joel Kitching: > 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 > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php