Re: OOP, Classes, Sharing Code

From: Date: Mon, 28 Jun 2004 22:16:37 +0000
Subject: Re: OOP, Classes, Sharing Code
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-189189@lists.php.net to get a copy of this message
Look correct from my point of view... class Portfolio { var $portfolioID ; var $albums = array () ; function Portfolio ( $newID ) {
      $this->portfolioID = $newID ;
} function addAlbum ( $album ) {
      $this->albums[] = $album ;
} function getAlbum () {
      return current ( $this->album ) ;
} .... } some knowlege on the iterator pattern is required though.... But you could even use a stack ( which i prefer ) class main { var $stack = NULL ; function create ( $ID ) {
      $this->stack = new stack ( $ID , $this->stack );
} function remove ( $ID ) {
      $this->stack = $this->stack->remove();
} function getID () {
      return $this->stack->getID();
} } class stack { var $ID ; var $prev = NULL ; function stack ( $ID , $prev ) {
      $this->ID = $ID ;
      $this->prev = $prev ;
} function getID () {
      return $this->ID ;
} function remove () {
      return $this->prev ;
} } $foo = new main(); $foo->create( 100 ); $foo->create( 200 );
echo $foo->getID();    // 200
$foo->remove(); $foo->create( 300 );
echo $foo->getID();    // 300
$foo->remove();
echo $foo->getID();    // 100
$foo->remove(); unset ( $foo ); [...]
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;
} [...]


« previous php.general (#189189) next »