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

List:       php-general
Subject:    Re: [PHP] OOP, Classes, Sharing Code
From:       Gabriel Birke <birke () kontor4 ! de>
Date:       2004-06-29 7:28:22
Message-ID: E693C8CB-C99D-11D8-A1D9-003065FA313E () kontor4 ! de
[Download RAW message or body]

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


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

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