Hi,
ich habe mir folgende Seite durchgelesen:
OOP mit PHP5
und mir dann für meine Bewertungen folgendes gebaut (s. unten)
Weshalb benötigt man denn noch die Klasse Vote? Könnte man nicht direkt
$produkt->getVotings() bzw. $produkt->getAverageVoting() aufrufen?
	
							
						
					ich habe mir folgende Seite durchgelesen:
OOP mit PHP5
und mir dann für meine Bewertungen folgendes gebaut (s. unten)
Weshalb benötigt man denn noch die Klasse Vote? Könnte man nicht direkt
$produkt->getVotings() bzw. $produkt->getAverageVoting() aufrufen?
PHP-Code:
	
	
interface Votable{
    
    public function getVotings();
    public function getAverageVote();
    
}
class Vote{
    
    private $type;
    
    public function __construct(Votable $type){
        $this->type = $type;
    }
    
    public function getVotings(){
        echo $this->type->getVotings();
    }
    
    public function getAverageVote(){
        echo $this->type->getAverageVote();
    }
    
}
class Product implements Votable{
    
    public function getVotings() {
        return 'alle Produktbewertungen';
    }
    
    public function getAverageVote() {
        return 'durchschnittliche Produktbewertung';
    }
    
    public static function findById($id){
        return new self;
    }
    
}
class Shop implements Votable{
    
    public function getVotings(){
        return 'alle Shopbewertungen';
    }
    
    public function getAverageVote() {
        return 'durchschnittliche Shopbewertung';
    }
    
}
/* Produktbewertung */
$pObj = Product::findById(10);
$product_vote = new Vote($pObj);
$product_vote->getVotings();
$product_vote->getAverageVote();
/* Shopbewertung */
$sObj = new Shop;
$shop_vote = new Vote($sObj);
$shop_vote->getVotings();
$shop_vote->getAverageVote(); 
 
          
Kommentar