Skip to content

Commit

Permalink
Added More pattern UMLs
Browse files Browse the repository at this point in the history
  • Loading branch information
John Webb committed Jul 31, 2014
1 parent 3a35fa7 commit de431c5
Show file tree
Hide file tree
Showing 33 changed files with 1,508 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Behavioral/ChainOfResponsibilities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt ChainOfResponsibility UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/Command/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Command UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/Iterator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Iterator UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/Mediator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Mediator UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/Memento/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Momento UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/NullObject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt NullObject UML Diagram](uml/uml.png)
6 changes: 5 additions & 1 deletion Behavioral/Observer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Observer UML Diagram](uml/uml.png)
3 changes: 3 additions & 0 deletions Behavioral/Specification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Specification UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/State/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt State UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/Strategy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Strategy UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/TemplateMethod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt TemplateMethod UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Behavioral/Visitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Visitor UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Creational/AbstractFactory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt AbstractFactory UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Creational/Builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ Note: Builders have often a fluent interface, see the mock builder of PHPUnit fo
## Examples

* PHPUnit: Mock Builder

## UML Diagram

![Alt Builder UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Creational/FactoryMethod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt FactoryMethod UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Creational/Multiton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Multiton UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Creational/Pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Pool UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Creational/Prototype/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Prototype UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Creational/SimpleFactory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt SimpleFactory UML Diagram](uml/uml.png)
6 changes: 5 additions & 1 deletion Creational/Singleton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt Singleton UML Diagram](uml/uml.png)
4 changes: 4 additions & 0 deletions Creational/StaticFactory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

![Alt StaticFactory UML Diagram](uml/uml.png)
13 changes: 13 additions & 0 deletions More/Delegation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Delegation

## Purpose

...

## Examples

...

## UML Diagram

![Alt Delegation UML Diagram](uml/uml.png)
21 changes: 21 additions & 0 deletions More/Delegation/uml/Delegation.uml
Original file line number Diff line number Diff line change
@@ -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>

Binary file added More/Delegation/uml/uml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit de431c5

Please sign in to comment.