Create("square"); $circle = $maker->Create("circle"); $square->Draw(); echo "\n"; $circle->Draw(); echo "\n"; abstract class ShapeFactory { protected static $types = array(); public static function Register($type, $class) { self::$types[$type]=$class; } public static function IsRegistered($type) { if (isset(self::$types[$type])) return true; else return false; } public static function Create($type) { if (isset(self::$types[$type]) && class_exists(self::$types[$type])) return new self::$types[$type]; else return null; } } ShapeFactory::Register("square","Square"); ShapeFactory::Register("circle","Circle"); $a_square = ShapeFactory::Create("square"); $a_circle = ShapeFactory::Create("circle"); $a_square->Draw(); echo "\n"; $a_circle->Draw(); echo "\n"; ?>