mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-01 12:40:11 +02:00
removed ...Interface suffix and added method to interface
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace DesignPatterns\Creational\StaticFactory;
|
||||
|
||||
class FormatNumber implements FormatterInterface
|
||||
class FormatNumber implements Formatter
|
||||
{
|
||||
public function format(string $input): string
|
||||
{
|
||||
return number_format($input);
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace DesignPatterns\Creational\StaticFactory;
|
||||
|
||||
class FormatString implements FormatterInterface
|
||||
class FormatString implements Formatter
|
||||
{
|
||||
public function format(string $input): string
|
||||
{
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
|
8
Creational/StaticFactory/Formatter.php
Normal file
8
Creational/StaticFactory/Formatter.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Creational\StaticFactory;
|
||||
|
||||
interface Formatter
|
||||
{
|
||||
public function format(string $input): string;
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Creational\StaticFactory;
|
||||
|
||||
interface FormatterInterface
|
||||
{
|
||||
}
|
@@ -14,7 +14,7 @@ Examples
|
||||
--------
|
||||
|
||||
- Zend Framework: ``Zend_Cache_Backend`` or ``_Frontend`` use a factory
|
||||
method create cache backends or frontends
|
||||
method to create cache backends and frontends
|
||||
|
||||
UML Diagram
|
||||
-----------
|
||||
@@ -34,9 +34,9 @@ StaticFactory.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
FormatterInterface.php
|
||||
Formatter.php
|
||||
|
||||
.. literalinclude:: FormatterInterface.php
|
||||
.. literalinclude:: Formatter.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
|
@@ -11,15 +11,13 @@ final class StaticFactory
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return FormatterInterface
|
||||
* @return Formatter
|
||||
*/
|
||||
public static function factory(string $type): FormatterInterface
|
||||
public static function factory(string $type): Formatter
|
||||
{
|
||||
if ($type == 'number') {
|
||||
return new FormatNumber();
|
||||
}
|
||||
|
||||
if ($type == 'string') {
|
||||
} elseif ($type == 'string') {
|
||||
return new FormatString();
|
||||
}
|
||||
|
||||
|
@@ -1,36 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Diagram>
|
||||
<ID>PHP</ID>
|
||||
<OriginalElement>\DesignPatterns\Creational\StaticFactory\FormatNumber</OriginalElement>
|
||||
<nodes>
|
||||
<node x="114.0" y="77.0">\DesignPatterns\Creational\StaticFactory\FormatNumber</node>
|
||||
<node x="-8.0" y="149.0">\DesignPatterns\Creational\StaticFactory\StaticFactory</node>
|
||||
<node x="0.0" y="77.0">\DesignPatterns\Creational\StaticFactory\FormatString</node>
|
||||
<node x="43.75" y="0.0">\DesignPatterns\Creational\StaticFactory\FormatterInterface</node>
|
||||
</nodes>
|
||||
<notes />
|
||||
<edges>
|
||||
<edge source="\DesignPatterns\Creational\StaticFactory\FormatString" target="\DesignPatterns\Creational\StaticFactory\FormatterInterface">
|
||||
<point x="0.0" y="-13.5" />
|
||||
<point x="47.0" y="52.0" />
|
||||
<point x="75.0" y="52.0" />
|
||||
<point x="-31.25" y="13.5" />
|
||||
</edge>
|
||||
<edge source="\DesignPatterns\Creational\StaticFactory\FormatNumber" target="\DesignPatterns\Creational\StaticFactory\FormatterInterface">
|
||||
<point x="0.0" y="-13.5" />
|
||||
<point x="165.5" y="52.0" />
|
||||
<point x="137.5" y="52.0" />
|
||||
<point x="31.25" y="13.5" />
|
||||
</edge>
|
||||
</edges>
|
||||
<settings layout="Hierarchic Group" zoom="1.0" x="108.5" y="98.0" />
|
||||
<SelectedNodes />
|
||||
<Categories>
|
||||
<Category>Fields</Category>
|
||||
<Category>Constants</Category>
|
||||
<Category>Constructors</Category>
|
||||
<Category>Methods</Category>
|
||||
</Categories>
|
||||
<VISIBILITY>private</VISIBILITY>
|
||||
</Diagram>
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Diagram>
|
||||
<ID>PHP</ID>
|
||||
<OriginalElement>\DesignPatterns\Creational\StaticFactory\FormatNumber</OriginalElement>
|
||||
<nodes>
|
||||
<node x="0.0" y="101.0">\DesignPatterns\Creational\StaticFactory\FormatString</node>
|
||||
<node x="0.0" y="197.0">\DesignPatterns\Creational\StaticFactory\StaticFactory</node>
|
||||
<node x="79.5" y="0.0">\DesignPatterns\Creational\StaticFactory\Formatter</node>
|
||||
<node x="159.0" y="101.0">\DesignPatterns\Creational\StaticFactory\FormatNumber</node>
|
||||
</nodes>
|
||||
<notes />
|
||||
<edges>
|
||||
<edge source="\DesignPatterns\Creational\StaticFactory\FormatString" target="\DesignPatterns\Creational\StaticFactory\Formatter">
|
||||
<point x="0.0" y="-25.5" />
|
||||
<point x="69.5" y="76.0" />
|
||||
<point x="114.25" y="76.0" />
|
||||
<point x="-34.75" y="25.5" />
|
||||
</edge>
|
||||
<edge source="\DesignPatterns\Creational\StaticFactory\FormatNumber" target="\DesignPatterns\Creational\StaticFactory\Formatter">
|
||||
<point x="0.0" y="-25.5" />
|
||||
<point x="228.5" y="76.0" />
|
||||
<point x="183.75" y="76.0" />
|
||||
<point x="34.75" y="25.5" />
|
||||
</edge>
|
||||
</edges>
|
||||
<settings layout="Hierarchic Group" zoom="1.0" x="128.0" y="102.0" />
|
||||
<SelectedNodes />
|
||||
<Categories>
|
||||
<Category>Fields</Category>
|
||||
<Category>Constants</Category>
|
||||
<Category>Constructors</Category>
|
||||
<Category>Methods</Category>
|
||||
</Categories>
|
||||
<VISIBILITY>private</VISIBILITY>
|
||||
</Diagram>
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 24 KiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 41 KiB |
Reference in New Issue
Block a user