Factory Pattern

<?php
interface GirlInterface{
function get_name();
function get_hair_color();
}

class Girl implements GirlInterface{
protected $_name,$_hair_color;
public function __construct($name,$hair_color){
$this->_name = $name;
$this->_hair_color = $hair_color;
}
public function get_name(){
return $this->_name;
}
public function get_hair_color(){
return $this->_hair_color;
}
}

class GirlFactory{
public static function Create($name,$hair_color){
return new Girl($name,$hair_color);
}
}

echo '~~~~~~~~~~~~~ Factory Example: ~~~~~~~~~~~~~';
$gf = GirlFactory::Create('Tanya','Red');
echo "Girl's name: {$gf->get_name()}<br>";
echo "Girl's hair: {$gf->get_hair_color()}<br><br>";
?>

0 Comments

You must be logged in to post a comment.