mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 12:10:10 +02:00
Added More pattern UMLs
This commit is contained in:
@@ -10,3 +10,7 @@ To build a chain of objects to handle a call. If one object cannot handle a call
|
||||
* a Spam filter
|
||||
* Caching: first object is an instance of e.g. a Memcached Interface, if that "misses" it delegates the call to the database interface
|
||||
* Yii Framework: CFilterChain is a chain of controller action filters. the executing point is passed from one filter to the next along the chain, and only if all filters say "yes", the action can be invoked at last.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -15,3 +15,7 @@ Command can also be aggregated to combine more complex commands with minimum cop
|
||||
* A text editor : all events are Command which can be undone, stacked and saved.
|
||||
* Symfony2: SF2 Commands that can be run from the CLI are built with just the Command pattern in mind
|
||||
* big CLI tools use subcommands to distribute various tasks and pack them in "modules", each of these can be implemented with the Command pattern (e.g. vagrant)
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -11,3 +11,7 @@ To make an object iterable and to make it appear like a collection of objects.
|
||||
## Note
|
||||
|
||||
Standard PHP Library (SPL) defines an interface Iterator which is best suited for this! Often you would want to implement the Countable interface too, to allow `count($object)` on your iterable object
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -9,3 +9,7 @@ like a controller (but not in the sense of the MVC).
|
||||
All components (called Colleague) are only coupled to the MediatorInterface and
|
||||
it is a good thing because in OOP, one good friend is better than many. This
|
||||
is the key-feature of this pattern.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -16,3 +16,7 @@ When using this pattern, care should be taken if the originator may change other
|
||||
|
||||
* The seed of a pseudorandom number generator
|
||||
* The state in a finite state machine
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -18,3 +18,7 @@ a statement like `if (!is_null($obj)) { $obj->callSomething(); }` anymore.
|
||||
* Symfony2: null output in Symfony/Console
|
||||
* null handler in a Chain of Responsibilities pattern
|
||||
* null command in a Command pattern
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -11,4 +11,8 @@ To implement a publish/subscribe behaviour to an object, whenever a "Subject" ob
|
||||
|
||||
## Note
|
||||
|
||||
PHP already defines two interfaces that can help to implement this pattern: SplObserver and SplSubject.
|
||||
PHP already defines two interfaces that can help to implement this pattern: SplObserver and SplSubject.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -5,3 +5,6 @@
|
||||
Builds a clear specification of business rules, where objects can be checked against. The composite specification class has
|
||||
one method called `isSatisfiedBy` that returns either true or false depending on whether the given object satisfies the specification.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -3,3 +3,7 @@
|
||||
## Purpose
|
||||
|
||||
Encapsulate varying behavior for the same routine based on an object's state. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -14,3 +14,7 @@ To separate strategies and to enable fast switching between them. Also this patt
|
||||
|
||||
* sorting a list of objects, one strategy by date, the other by id
|
||||
* simplify unit testing: e.g. switching between file and in-memory storage
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -12,3 +12,7 @@ How? With abstraction of course.
|
||||
In other words, this is a skeleton of algorithm, well-suited for framework libraries. The user has just to implement one method and the superclass do the job.
|
||||
|
||||
It is an easy way to decouple concrete classes and reduce copy-paste, that's why you'll find it everywhere.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -6,3 +6,7 @@ The Visitor Pattern lets you outsource operations on objects to other objects. T
|
||||
But classes have to define a contract to allow visitors (the `Role::accept` method in the example).
|
||||
|
||||
The contract is an abstract class but you can have also a clean interface. In that case, each Visitor has to choose itself which method to invoke on the visitor.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -4,3 +4,7 @@
|
||||
|
||||
To create series of related or dependent objects without specifying their concrete classes.
|
||||
Usually the created classes all implement the same interface. The client of the abstract factory does not care about how these objects are created, he just knows how they go together.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -13,3 +13,7 @@ Note: Builders have often a fluent interface, see the mock builder of PHPUnit fo
|
||||
## Examples
|
||||
|
||||
* PHPUnit: Mock Builder
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -9,3 +9,7 @@ For simple case, this abstract class could be just an interface
|
||||
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.
|
||||
|
||||
It means the FactoryMethod class depends on abstractions, not concrete classes. This is the real trick compared to SimpleFactory or StaticFactory.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -10,3 +10,7 @@ To have only a list of named instances that are used, like a singleton but with
|
||||
|
||||
* 2 DB Connectors, e.g. one for MySQL, the other for SQLite
|
||||
* multiple Loggers (one for debug messages, one for errors)
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -6,3 +6,7 @@ The **object pool pattern** is a software creational design pattern that uses a
|
||||
Object pooling can offer a significant performance boost in situations where the cost of initializing a class instance is high, the rate of instantiation of a class is high, and the number of instances in use at any one time is low. The pooled object is obtained in predictable time when creation of the new objects (especially over network) may take variable time.
|
||||
|
||||
However these benefits are mostly true for objects that are expensive with respect to time, such as database connections, socket connections, threads and large graphic objects like fonts or bitmaps. In certain situations, simple object pooling (that hold no external resources, but only occupy memory) may not be efficient and could decrease performance.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -7,3 +7,7 @@ To avoid the cost of creating objects the standard way (new Foo()) and instead c
|
||||
## Examples
|
||||
|
||||
* Large amounts of data (e.g. create 1,000,000 rows in a database at once via a ORM)
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -7,3 +7,7 @@ ConcreteFactory is a simple factory pattern.
|
||||
It differs from the static factory because it is NOT static and as you know: static => global => evil!
|
||||
|
||||
Therefore, you can have multiple factories, differently parametrized, you can subclass it and you can mock-up it.
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -14,4 +14,8 @@ To have only one instance of this object in the application that will handle all
|
||||
|
||||
## Diagram
|
||||
|
||||
<img src="http://yuml.me/diagram/scruffy/class/[Singleton|-instance: Singleton|+getInstance(): Singleton;-__construct(): void;-__clone(): void;-__wakeup(): void]" >
|
||||
<img src="http://yuml.me/diagram/scruffy/class/[Singleton|-instance: Singleton|+getInstance(): Singleton;-__construct(): void;-__clone(): void;-__wakeup(): void]" >
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
@@ -9,3 +9,7 @@ method to create all types of objects it can create. It is usually named `factor
|
||||
## Examples
|
||||
|
||||
* Zend Framework: `Zend_Cache_Backend` or `_Frontend` use a factory method create cache backends or frontends
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
13
More/Delegation/README.md
Normal file
13
More/Delegation/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Delegation
|
||||
|
||||
## Purpose
|
||||
|
||||
...
|
||||
|
||||
## Examples
|
||||
|
||||
...
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
21
More/Delegation/uml/Delegation.uml
Normal file
21
More/Delegation/uml/Delegation.uml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Diagram>
|
||||
<ID>PHP</ID>
|
||||
<OriginalElement>\DesignPatterns\More\Delegation\JuniorDeveloper</OriginalElement>
|
||||
<nodes>
|
||||
<node x="-8.0" y="134.0">\DesignPatterns\More\Delegation\JuniorDeveloper</node>
|
||||
<node x="0.0" y="0.0">\DesignPatterns\More\Delegation\TeamLead</node>
|
||||
</nodes>
|
||||
<notes />
|
||||
<edges />
|
||||
<settings layout="Hierarchic Group" zoom="1.0" x="68.5" y="90.5" />
|
||||
<SelectedNodes />
|
||||
<Categories>
|
||||
<Category>Fields</Category>
|
||||
<Category>Constants</Category>
|
||||
<Category>Constructors</Category>
|
||||
<Category>Methods</Category>
|
||||
</Categories>
|
||||
<VISIBILITY>private</VISIBILITY>
|
||||
</Diagram>
|
||||
|
BIN
More/Delegation/uml/uml.png
Normal file
BIN
More/Delegation/uml/uml.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
196
More/Delegation/uml/uml.svg
Normal file
196
More/Delegation/uml/uml.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 28 KiB |
@@ -10,3 +10,7 @@ Repository also supports the objective of achieving a clean separation and one-w
|
||||
|
||||
* Doctrine 2 ORM: there is Repository that mediates between Entity and DBAL and contains methods to retrieve objects
|
||||
* Laravel Framework
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
28
More/Repository/uml/Repository.uml
Normal file
28
More/Repository/uml/Repository.uml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Diagram>
|
||||
<ID>PHP</ID>
|
||||
<OriginalElement>\DesignPatterns\Repository\PostRepository</OriginalElement>
|
||||
<nodes>
|
||||
<node x="415.0" y="0.0">\DesignPatterns\Repository\Storage</node>
|
||||
<node x="405.0" y="137.0">\DesignPatterns\Repository\MemoryStorage</node>
|
||||
<node x="0.0" y="0.0">\DesignPatterns\Repository\Post</node>
|
||||
<node x="0.0" y="373.0">\DesignPatterns\Repository\PostRepository</node>
|
||||
</nodes>
|
||||
<notes />
|
||||
<edges>
|
||||
<edge source="\DesignPatterns\Repository\MemoryStorage" target="\DesignPatterns\Repository\Storage">
|
||||
<point x="0.0" y="-74.5" />
|
||||
<point x="0.0" y="43.5" />
|
||||
</edge>
|
||||
</edges>
|
||||
<settings layout="Hierarchic Group" zoom="0.7394636015325671" x="299.5" y="251.0" />
|
||||
<SelectedNodes />
|
||||
<Categories>
|
||||
<Category>Fields</Category>
|
||||
<Category>Constants</Category>
|
||||
<Category>Constructors</Category>
|
||||
<Category>Methods</Category>
|
||||
</Categories>
|
||||
<VISIBILITY>private</VISIBILITY>
|
||||
</Diagram>
|
||||
|
BIN
More/Repository/uml/uml.png
Normal file
BIN
More/Repository/uml/uml.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
687
More/Repository/uml/uml.svg
Normal file
687
More/Repository/uml/uml.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 89 KiB |
@@ -14,3 +14,7 @@ Service Locator object on bootstrap.
|
||||
## Examples
|
||||
|
||||
* Zend Framework 2 uses Service Locator to create and share services used in the framework(i.e. EventManager, ModuleManager, all custom user services provided by modules, etc...)
|
||||
|
||||
## UML Diagram
|
||||
|
||||

|
38
More/ServiceLocator/uml/ServiceLocator.uml
Normal file
38
More/ServiceLocator/uml/ServiceLocator.uml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Diagram>
|
||||
<ID>PHP</ID>
|
||||
<OriginalElement>\DesignPatterns\More\ServiceLocator\DatabaseServiceInterface</OriginalElement>
|
||||
<nodes>
|
||||
<node x="276.0" y="0.0">\DesignPatterns\More\ServiceLocator\DatabaseServiceInterface</node>
|
||||
<node x="22.5" y="408.0">\DesignPatterns\More\ServiceLocator\LogService</node>
|
||||
<node x="0.0" y="117.0">\DesignPatterns\More\ServiceLocator\ServiceLocator</node>
|
||||
<node x="41.5" y="0.0">\DesignPatterns\More\ServiceLocator\ServiceLocatorInterface</node>
|
||||
<node x="0.0" y="331.0">\DesignPatterns\More\ServiceLocator\LogServiceInterface</node>
|
||||
<node x="298.5" y="77.0">\DesignPatterns\More\ServiceLocator\DatabaseService</node>
|
||||
</nodes>
|
||||
<notes />
|
||||
<edges>
|
||||
<edge source="\DesignPatterns\More\ServiceLocator\ServiceLocator" target="\DesignPatterns\More\ServiceLocator\ServiceLocatorInterface">
|
||||
<point x="0.0" y="-84.5" />
|
||||
<point x="0.0" y="33.5" />
|
||||
</edge>
|
||||
<edge source="\DesignPatterns\More\ServiceLocator\DatabaseService" target="\DesignPatterns\More\ServiceLocator\DatabaseServiceInterface">
|
||||
<point x="0.0" y="-13.5" />
|
||||
<point x="0.0" y="13.5" />
|
||||
</edge>
|
||||
<edge source="\DesignPatterns\More\ServiceLocator\LogService" target="\DesignPatterns\More\ServiceLocator\LogServiceInterface">
|
||||
<point x="0.0" y="-13.5" />
|
||||
<point x="0.0" y="13.5" />
|
||||
</edge>
|
||||
</edges>
|
||||
<settings layout="Hierarchic Group" zoom="0.8483516483516483" x="217.0" y="217.5" />
|
||||
<SelectedNodes />
|
||||
<Categories>
|
||||
<Category>Fields</Category>
|
||||
<Category>Constants</Category>
|
||||
<Category>Constructors</Category>
|
||||
<Category>Methods</Category>
|
||||
</Categories>
|
||||
<VISIBILITY>private</VISIBILITY>
|
||||
</Diagram>
|
||||
|
BIN
More/ServiceLocator/uml/uml.png
Normal file
BIN
More/ServiceLocator/uml/uml.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
432
More/ServiceLocator/uml/uml.svg
Normal file
432
More/ServiceLocator/uml/uml.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 53 KiB |
Reference in New Issue
Block a user