diff --git a/Creational/FactoryMethod/Bicycle.php b/Creational/FactoryMethod/Bicycle.php deleted file mode 100644 index 95aacbf..0000000 --- a/Creational/FactoryMethod/Bicycle.php +++ /dev/null @@ -1,16 +0,0 @@ -color = $rgb; - } -} diff --git a/Creational/FactoryMethod/CarFerrari.php b/Creational/FactoryMethod/CarFerrari.php deleted file mode 100644 index dfb9eca..0000000 --- a/Creational/FactoryMethod/CarFerrari.php +++ /dev/null @@ -1,16 +0,0 @@ -color = $rgb; - } -} diff --git a/Creational/FactoryMethod/CarMercedes.php b/Creational/FactoryMethod/CarMercedes.php deleted file mode 100644 index bc6e337..0000000 --- a/Creational/FactoryMethod/CarMercedes.php +++ /dev/null @@ -1,21 +0,0 @@ -color = $rgb; - } - - public function addAMGTuning() - { - // do additional tuning here - } -} diff --git a/Creational/FactoryMethod/FactoryMethod.php b/Creational/FactoryMethod/FactoryMethod.php deleted file mode 100644 index d999f7b..0000000 --- a/Creational/FactoryMethod/FactoryMethod.php +++ /dev/null @@ -1,19 +0,0 @@ -createVehicle($type); - $obj->setColor('black'); - - return $obj; - } -} diff --git a/Creational/FactoryMethod/FileLogger.php b/Creational/FactoryMethod/FileLogger.php new file mode 100644 index 0000000..96aaa22 --- /dev/null +++ b/Creational/FactoryMethod/FileLogger.php @@ -0,0 +1,21 @@ +filePath = $filePath; + } + + public function log(string $message) + { + file_put_contents($this->filePath, $message . PHP_EOL, FILE_APPEND); + } +} diff --git a/Creational/FactoryMethod/FileLoggerFactory.php b/Creational/FactoryMethod/FileLoggerFactory.php new file mode 100644 index 0000000..6922c00 --- /dev/null +++ b/Creational/FactoryMethod/FileLoggerFactory.php @@ -0,0 +1,21 @@ +filePath = $filePath; + } + + public function createLogger(): Logger + { + return new FileLogger($this->filePath); + } +} diff --git a/Creational/FactoryMethod/GermanFactory.php b/Creational/FactoryMethod/GermanFactory.php deleted file mode 100644 index 7abb750..0000000 --- a/Creational/FactoryMethod/GermanFactory.php +++ /dev/null @@ -1,22 +0,0 @@ -addAMGTuning(); - - return $carMercedes; - default: - throw new \InvalidArgumentException("$type is not a valid vehicle"); - } - } -} diff --git a/Creational/FactoryMethod/ItalianFactory.php b/Creational/FactoryMethod/ItalianFactory.php deleted file mode 100644 index 58a54f4..0000000 --- a/Creational/FactoryMethod/ItalianFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -create(FactoryMethod::CHEAP); + $loggerFactory = new StdoutLoggerFactory(); + $logger = $loggerFactory->createLogger(); - $this->assertInstanceOf(Bicycle::class, $result); + $this->assertInstanceOf(StdoutLogger::class, $logger); } - public function testCanCreateFastVehicleInGermany() + public function testCanCreateFileLogging() { - $factory = new GermanFactory(); - $result = $factory->create(FactoryMethod::FAST); + $loggerFactory = new FileLoggerFactory(sys_get_temp_dir()); + $logger = $loggerFactory->createLogger(); - $this->assertInstanceOf(CarMercedes::class, $result); - } - - public function testCanCreateCheapVehicleInItaly() - { - $factory = new ItalianFactory(); - $result = $factory->create(FactoryMethod::CHEAP); - - $this->assertInstanceOf(Bicycle::class, $result); - } - - public function testCanCreateFastVehicleInItaly() - { - $factory = new ItalianFactory(); - $result = $factory->create(FactoryMethod::FAST); - - $this->assertInstanceOf(CarFerrari::class, $result); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage spaceship is not a valid vehicle - */ - public function testUnknownType() - { - (new ItalianFactory())->create('spaceship'); + $this->assertInstanceOf(FileLogger::class, $logger); } } diff --git a/Creational/FactoryMethod/VehicleInterface.php b/Creational/FactoryMethod/VehicleInterface.php deleted file mode 100644 index 9f5fb15..0000000 --- a/Creational/FactoryMethod/VehicleInterface.php +++ /dev/null @@ -1,8 +0,0 @@ - PHP - \DesignPatterns\Creational\FactoryMethod\GermanFactory + \DesignPatterns\Creational\FactoryMethod\StdoutLoggerFactory - \DesignPatterns\Creational\FactoryMethod\FactoryMethod - \DesignPatterns\Creational\FactoryMethod\Bicycle - \DesignPatterns\Creational\FactoryMethod\CarFerrari - \DesignPatterns\Creational\FactoryMethod\ItalianFactory - \DesignPatterns\Creational\FactoryMethod\CarMercedes - \DesignPatterns\Creational\FactoryMethod\GermanFactory - \DesignPatterns\Creational\FactoryMethod\VehicleInterface + \DesignPatterns\Creational\FactoryMethod\LoggerFactory + \DesignPatterns\Creational\FactoryMethod\StdoutLoggerFactory + \DesignPatterns\Creational\FactoryMethod\FileLogger + \DesignPatterns\Creational\FactoryMethod\FileLoggerFactory + \DesignPatterns\Creational\FactoryMethod\StdoutLogger + \DesignPatterns\Creational\FactoryMethod\Logger - + - - - + + + - - - - - + + + + + - - - - - + - - - + + + - - - - - + + + + + - - + + + \DesignPatterns\Creational\FactoryMethod\FileLogger + \DesignPatterns\Creational\FactoryMethod\StdoutLogger + \DesignPatterns\Creational\FactoryMethod\Logger + Fields + Constants Constructors Methods diff --git a/Creational/FactoryMethod/uml/uml.png b/Creational/FactoryMethod/uml/uml.png index b705b22..8f33b88 100644 Binary files a/Creational/FactoryMethod/uml/uml.png and b/Creational/FactoryMethod/uml/uml.png differ diff --git a/Creational/FactoryMethod/uml/uml.svg b/Creational/FactoryMethod/uml/uml.svg index 6ddd586..5463cb1 100644 --- a/Creational/FactoryMethod/uml/uml.svg +++ b/Creational/FactoryMethod/uml/uml.svg @@ -1,974 +1,50 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - createVehicle(type) - - - - - - - - - - - - - create(type) - - - - - - - - - - - - - FactoryMethod - - - FactoryMethod - - - - - - - - - - - - - - - - - - - - - - createVehicle(type) - - - - - - - - - - - - - - - - create(type) - - - - - - - - - - - - - FactoryMethod - - - FactoryMethod - - - - - - - - - - - - - - - - - - - - - - - - - color - - - - - - - - - - - - - - - - setColor(rgb) - - - - - - - - - - - - - Bicycle - - - Bicycle - - - - - - - - - - - - - - - - - - - - - - color - - - - - - - - - - - - - - - - - - - setColor(rgb) - - - - - - - - - - - - - Bicycle - - - Bicycle - - - - - - - - - - - - - - - - - - - - - - - - - color - - - - - - - - - - - - - - - - setColor(rgb) - - - - - - - - - - - - - CarFerrari - - - CarFerrari - - - - - - - - - - - - - - - - - - - - - - color - - - - - - - - - - - - - - - - - - - setColor(rgb) - - - - - - - - - - - - - CarFerrari - - - CarFerrari - - - - - - - - - - - - - - - - - - - - - - createVehicle(type) - - - - - - - - - - - - - ItalianFactory - - - ItalianFactory - - - - - - - - - - - - - - - - - - - - - - createVehicle(type) - - - - - - - - - - - - - ItalianFactory - - - ItalianFactory - - - - - - - - - - - - - - - - - - - - - - - - - color - - - - - - - - - - - - - - - - setColor(rgb) - - - - - - - - - - - - - addAMGTuning() - - - - - - - - - - - - - CarMercedes - - - CarMercedes - - - - - - - - - - - - - - - - - - - - - - color - - - - - - - - - - - - - - - - - - - setColor(rgb) - - - - - - - - - - - - - - - - addAMGTuning() - - - - - - - - - - - - - CarMercedes - - - CarMercedes - - - - - - - - - - - - - - - - - - - - - - createVehicle(type) - - - - - - - - - - - - - GermanFactory - - - GermanFactory - - - - - - - - - - - - - - - - - - - - - - createVehicle(type) - - - - - - - - - - - - - GermanFactory - - - GermanFactory - - - - - - - - - - - - - - - - - - - - - - setColor(rgb) - - - - - - - - - - - - - VehicleInterface - - - VehicleInterface - - - - - - - - - - - - - - - - - - - - - - setColor(rgb) - - - - - - - - - - - - - VehicleInterface - - - VehicleInterface - - - - - - - - - - - - - - - - - + + + PHP + \DesignPatterns\Creational\FactoryMethod\StdoutLoggerFactory + + \DesignPatterns\Creational\FactoryMethod\LoggerFactory + \DesignPatterns\Creational\FactoryMethod\StdoutLoggerFactory + \DesignPatterns\Creational\FactoryMethod\FileLogger + \DesignPatterns\Creational\FactoryMethod\FileLoggerFactory + \DesignPatterns\Creational\FactoryMethod\StdoutLogger + \DesignPatterns\Creational\FactoryMethod\Logger + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fields + Constants + Constructors + Methods + + private + + diff --git a/locale/ca/LC_MESSAGES/Creational/FactoryMethod/README.po b/locale/ca/LC_MESSAGES/Creational/FactoryMethod/README.po index 75c9f89..d409bec 100644 --- a/locale/ca/LC_MESSAGES/Creational/FactoryMethod/README.po +++ b/locale/ca/LC_MESSAGES/Creational/FactoryMethod/README.po @@ -32,7 +32,7 @@ msgstr "" #: ../../Creational/FactoryMethod/README.rst:12 msgid "" "This pattern is a \"real\" Design Pattern because it achieves the " -"\"Dependency Inversion Principle\" a.k.a the \"D\" in S.O.L.I.D principles." +"Dependency Inversion principle a.k.a the \"D\" in SOLID principles." msgstr "" #: ../../Creational/FactoryMethod/README.rst:15 diff --git a/locale/de/LC_MESSAGES/Creational/FactoryMethod/README.po b/locale/de/LC_MESSAGES/Creational/FactoryMethod/README.po index 0ce8e40..080c906 100644 --- a/locale/de/LC_MESSAGES/Creational/FactoryMethod/README.po +++ b/locale/de/LC_MESSAGES/Creational/FactoryMethod/README.po @@ -39,10 +39,10 @@ msgstr "" #: ../../Creational/FactoryMethod/README.rst:12 msgid "" "This pattern is a \"real\" Design Pattern because it achieves the " -"\"Dependency Inversion Principle\" a.k.a the \"D\" in S.O.L.I.D principles." +"Dependency Inversion principle a.k.a the \"D\" in SOLID principles." msgstr "" -"Dieses Muster ist ein \"echtes\" Muster, da es das \"D\" in S.O.L.I.D. " -"implementiert, das \"Dependency Inversion Prinzip\"." +"Dieses Muster ist ein \"echtes\" Muster, da es das \"D\" in SOLID " +"implementiert, das Dependency Inversion Prinzip." #: ../../Creational/FactoryMethod/README.rst:15 msgid "" diff --git a/locale/es/LC_MESSAGES/Creational/FactoryMethod/README.po b/locale/es/LC_MESSAGES/Creational/FactoryMethod/README.po index 274f32f..9ff261a 100644 --- a/locale/es/LC_MESSAGES/Creational/FactoryMethod/README.po +++ b/locale/es/LC_MESSAGES/Creational/FactoryMethod/README.po @@ -36,7 +36,7 @@ msgstr "" #: ../../Creational/FactoryMethod/README.rst:12 msgid "" "This pattern is a \"real\" Design Pattern because it achieves the " -"\"Dependency Inversion Principle\" a.k.a the \"D\" in S.O.L.I.D principles." +"Dependency Inversion principle a.k.a the \"D\" in SOLID principles." msgstr "" #: ../../Creational/FactoryMethod/README.rst:15 diff --git a/locale/es_MX/LC_MESSAGES/Creational/FactoryMethod/README.po b/locale/es_MX/LC_MESSAGES/Creational/FactoryMethod/README.po index 161f644..8945664 100644 --- a/locale/es_MX/LC_MESSAGES/Creational/FactoryMethod/README.po +++ b/locale/es_MX/LC_MESSAGES/Creational/FactoryMethod/README.po @@ -38,7 +38,7 @@ msgstr "" #: ../../Creational/FactoryMethod/README.rst:12 msgid "" "This pattern is a \"real\" Design Pattern because it achieves the Dependency " -"Inversion Principle\" a.k.a the \"D\" in S.O.L.I.D principles." +"Dependency Inversion principle a.k.a the \"D\" in SOLID principles." msgstr "" "Este es un patrón \"real\" de diseño porque realiza el Principio de " "Inversión de Dependencia, también conocido como la \"D\" de los principios S." diff --git a/locale/pl/LC_MESSAGES/Creational/FactoryMethod/README.po b/locale/pl/LC_MESSAGES/Creational/FactoryMethod/README.po index 1752486..9e5980a 100644 --- a/locale/pl/LC_MESSAGES/Creational/FactoryMethod/README.po +++ b/locale/pl/LC_MESSAGES/Creational/FactoryMethod/README.po @@ -35,7 +35,7 @@ msgstr "" #: ../../Creational/FactoryMethod/README.rst:12 msgid "" "This pattern is a \"real\" Design Pattern because it achieves the " -"\"Dependency Inversion Principle\" a.k.a the \"D\" in S.O.L.I.D principles." +"Dependency Inversion principle a.k.a the \"D\" in SOLID principles." msgstr "" "Ten wzorzec implementuje jedną z podstawowych zasad programowania obiektowego `SOLID `_ - \"D\" - zasadę odwrócenia zależności (ang. `Dependency inversion principle`)." diff --git a/locale/pt_BR/LC_MESSAGES/Creational/FactoryMethod/README.po b/locale/pt_BR/LC_MESSAGES/Creational/FactoryMethod/README.po index 9797e55..5e18e72 100644 --- a/locale/pt_BR/LC_MESSAGES/Creational/FactoryMethod/README.po +++ b/locale/pt_BR/LC_MESSAGES/Creational/FactoryMethod/README.po @@ -35,10 +35,10 @@ msgstr "" #: ../../Creational/FactoryMethod/README.rst:12 msgid "" "This pattern is a \"real\" Design Pattern because it achieves the " -"\"Dependency Inversion Principle\" a.k.a the \"D\" in S.O.L.I.D principles." +"Dependency Inversion principle a.k.a the \"D\" in SOLID principles." msgstr "" "Este padrão é um padrão de projetos de software \"real\" já que " -"trata o \"Princípio da inversão de dependências\" o \"D\" nos princípios S.O.L.I.D" +"trata o \"Princípio da inversão de dependências\" o \"D\" nos princípios SOLID" #: ../../Creational/FactoryMethod/README.rst:15 msgid "" diff --git a/locale/ru/LC_MESSAGES/Creational/FactoryMethod/README.po b/locale/ru/LC_MESSAGES/Creational/FactoryMethod/README.po index 26f030d..4d41e36 100644 --- a/locale/ru/LC_MESSAGES/Creational/FactoryMethod/README.po +++ b/locale/ru/LC_MESSAGES/Creational/FactoryMethod/README.po @@ -37,7 +37,7 @@ msgstr "" #: ../../Creational/FactoryMethod/README.rst:12 msgid "" "This pattern is a \"real\" Design Pattern because it achieves the " -"\"Dependency Inversion Principle\" a.k.a the \"D\" in S.O.L.I.D principles." +"Dependency Inversion principle a.k.a the \"D\" in SOLID principles." msgstr "" "Этот паттерн является «настоящим» Шаблоном Проектирования, потому что он " "следует «Принципу инверсии зависимостей\" ака \"D\" в `S.O.L.I.D