mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-01 12:40:11 +02:00
cs StaticFactory
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace DesignPatterns\StaticFactory;
|
||||
|
||||
class FormatNumber implements Formatter
|
||||
/**
|
||||
* Class FormatNumber
|
||||
*/
|
||||
class FormatNumber implements FormatterInterface
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace DesignPatterns\StaticFactory;
|
||||
|
||||
class FormatString implements Formatter
|
||||
/**
|
||||
* Class FormatString
|
||||
*/
|
||||
class FormatString implements FormatterInterface
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace DesignPatterns\StaticFactory;
|
||||
|
||||
interface Formatter
|
||||
/**
|
||||
* Class FormatterInterface
|
||||
*/
|
||||
interface FormatterInterface
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
@@ -14,16 +14,19 @@ namespace DesignPatterns\StaticFactory;
|
||||
* - Zend Framework: Zend_Cache_Backend or _Frontend use a factory method create cache backends or frontends
|
||||
*
|
||||
* Note1: Remember, static => global => evil
|
||||
* Note2: Cannot be subclassed or mock-uped or have multiple different instances
|
||||
* Note2: Cannot be subclassed or mock-upped or have multiple different instances
|
||||
*/
|
||||
class StaticFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* the parametrized function to get create an instance
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @static
|
||||
* @return Formatter
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return FormatterInterface
|
||||
*/
|
||||
public static function factory($type)
|
||||
{
|
||||
@@ -35,5 +38,4 @@ class StaticFactory
|
||||
|
||||
return new $className();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user