removed ...Interface suffix and added method to interface

This commit is contained in:
Dominik Liebler
2018-11-06 20:18:30 +01:00
parent 9910fdf111
commit b0ac02f01e
9 changed files with 136 additions and 260 deletions

View File

@@ -2,6 +2,10 @@
namespace DesignPatterns\Creational\StaticFactory; namespace DesignPatterns\Creational\StaticFactory;
class FormatNumber implements FormatterInterface class FormatNumber implements Formatter
{ {
public function format(string $input): string
{
return number_format($input);
}
} }

View File

@@ -2,6 +2,10 @@
namespace DesignPatterns\Creational\StaticFactory; namespace DesignPatterns\Creational\StaticFactory;
class FormatString implements FormatterInterface class FormatString implements Formatter
{ {
public function format(string $input): string
{
return $input;
}
} }

View File

@@ -0,0 +1,8 @@
<?php
namespace DesignPatterns\Creational\StaticFactory;
interface Formatter
{
public function format(string $input): string;
}

View File

@@ -1,7 +0,0 @@
<?php
namespace DesignPatterns\Creational\StaticFactory;
interface FormatterInterface
{
}

View File

@@ -14,7 +14,7 @@ Examples
-------- --------
- Zend Framework: ``Zend_Cache_Backend`` or ``_Frontend`` use a factory - 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 UML Diagram
----------- -----------
@@ -34,9 +34,9 @@ StaticFactory.php
:language: php :language: php
:linenos: :linenos:
FormatterInterface.php Formatter.php
.. literalinclude:: FormatterInterface.php .. literalinclude:: Formatter.php
:language: php :language: php
:linenos: :linenos:

View File

@@ -11,15 +11,13 @@ final class StaticFactory
/** /**
* @param string $type * @param string $type
* *
* @return FormatterInterface * @return Formatter
*/ */
public static function factory(string $type): FormatterInterface public static function factory(string $type): Formatter
{ {
if ($type == 'number') { if ($type == 'number') {
return new FormatNumber(); return new FormatNumber();
} } elseif ($type == 'string') {
if ($type == 'string') {
return new FormatString(); return new FormatString();
} }

View File

@@ -3,27 +3,27 @@
<ID>PHP</ID> <ID>PHP</ID>
<OriginalElement>\DesignPatterns\Creational\StaticFactory\FormatNumber</OriginalElement> <OriginalElement>\DesignPatterns\Creational\StaticFactory\FormatNumber</OriginalElement>
<nodes> <nodes>
<node x="114.0" y="77.0">\DesignPatterns\Creational\StaticFactory\FormatNumber</node> <node x="0.0" y="101.0">\DesignPatterns\Creational\StaticFactory\FormatString</node>
<node x="-8.0" y="149.0">\DesignPatterns\Creational\StaticFactory\StaticFactory</node> <node x="0.0" y="197.0">\DesignPatterns\Creational\StaticFactory\StaticFactory</node>
<node x="0.0" y="77.0">\DesignPatterns\Creational\StaticFactory\FormatString</node> <node x="79.5" y="0.0">\DesignPatterns\Creational\StaticFactory\Formatter</node>
<node x="43.75" y="0.0">\DesignPatterns\Creational\StaticFactory\FormatterInterface</node> <node x="159.0" y="101.0">\DesignPatterns\Creational\StaticFactory\FormatNumber</node>
</nodes> </nodes>
<notes /> <notes />
<edges> <edges>
<edge source="\DesignPatterns\Creational\StaticFactory\FormatString" target="\DesignPatterns\Creational\StaticFactory\FormatterInterface"> <edge source="\DesignPatterns\Creational\StaticFactory\FormatString" target="\DesignPatterns\Creational\StaticFactory\Formatter">
<point x="0.0" y="-13.5" /> <point x="0.0" y="-25.5" />
<point x="47.0" y="52.0" /> <point x="69.5" y="76.0" />
<point x="75.0" y="52.0" /> <point x="114.25" y="76.0" />
<point x="-31.25" y="13.5" /> <point x="-34.75" y="25.5" />
</edge> </edge>
<edge source="\DesignPatterns\Creational\StaticFactory\FormatNumber" target="\DesignPatterns\Creational\StaticFactory\FormatterInterface"> <edge source="\DesignPatterns\Creational\StaticFactory\FormatNumber" target="\DesignPatterns\Creational\StaticFactory\Formatter">
<point x="0.0" y="-13.5" /> <point x="0.0" y="-25.5" />
<point x="165.5" y="52.0" /> <point x="228.5" y="76.0" />
<point x="137.5" y="52.0" /> <point x="183.75" y="76.0" />
<point x="31.25" y="13.5" /> <point x="34.75" y="25.5" />
</edge> </edge>
</edges> </edges>
<settings layout="Hierarchic Group" zoom="1.0" x="108.5" y="98.0" /> <settings layout="Hierarchic Group" zoom="1.0" x="128.0" y="102.0" />
<SelectedNodes /> <SelectedNodes />
<Categories> <Categories>
<Category>Fields</Category> <Category>Fields</Category>

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