diff --git a/StaticFactory/FormatNumber.php b/StaticFactory/FormatNumber.php new file mode 100644 index 0000000..f7bf851 --- /dev/null +++ b/StaticFactory/FormatNumber.php @@ -0,0 +1,8 @@ + global => evil + * Note2: Cannot be subclassed or mock-uped or have multiple different instances */ -class FactoryMethod +class StaticFactory { + /** * the parametrized function to get create an instance * @@ -24,26 +27,13 @@ class FactoryMethod */ public static function factory($type) { - $className = 'Format' . ucfirst($type); - if ( ! class_exists($className)) { - throw new Exception('Missing format class.'); + $className = __NAMESPACE__ . '\Format' . ucfirst($type); + + if (!class_exists($className)) { + throw new \InvalidArgumentException('Missing format class.'); } return new $className(); } -} - -interface Formatter -{ } - -class FormatString implements Formatter -{ - -} - -class FormatNumber implements Formatter -{ - -}