jetzt muss ich nochmal nachfragen:
welchen Vorteil hat die Attributklasse?
welchen Vorteil hat die Attributklasse?
abstract class Product {
public static function factory($deviceType) {
$class = __CLASS__ . "_" . $deviceType;
if (class_exists($class)) {
return new $class();
}
throw new InvalidArgumentException("invalid device type");
}
public function fromArray(array $data) {
foreach ($data as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;
}
}
}
}
class Product_Handy extends Product {
public $description;
public static function findById($id){}
}
class Product_Navi extends Product {
public $title;
}
$product = Product::factory('Handy');
switch($type){
case 'Handy':
$product->getDescription();
break;
case 'Navi':
$product->getTitle();
break;
}
Kommentar