diff --git a/Behavioral/ChainOfResponsibilities/README.md b/Behavioral/ChainOfResponsibilities/README.md index 462f6c1..4d5b1d2 100644 --- a/Behavioral/ChainOfResponsibilities/README.md +++ b/Behavioral/ChainOfResponsibilities/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/Command/README.md b/Behavioral/Command/README.md index 748b84f..adf2de3 100644 --- a/Behavioral/Command/README.md +++ b/Behavioral/Command/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/Iterator/README.md b/Behavioral/Iterator/README.md index d364490..46e96b8 100644 --- a/Behavioral/Iterator/README.md +++ b/Behavioral/Iterator/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/Mediator/README.md b/Behavioral/Mediator/README.md index 5376000..818ff4c 100644 --- a/Behavioral/Mediator/README.md +++ b/Behavioral/Mediator/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/Memento/README.md b/Behavioral/Memento/README.md index 83ca2c0..4e3294e 100644 --- a/Behavioral/Memento/README.md +++ b/Behavioral/Memento/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/NullObject/README.md b/Behavioral/NullObject/README.md index 1e18d25..68f2bd0 100644 --- a/Behavioral/NullObject/README.md +++ b/Behavioral/NullObject/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/Observer/README.md b/Behavioral/Observer/README.md index c59a584..ccaeaca 100644 --- a/Behavioral/Observer/README.md +++ b/Behavioral/Observer/README.md @@ -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. \ No newline at end of file +PHP already defines two interfaces that can help to implement this pattern: SplObserver and SplSubject. + +## UML Diagram + +![Alt Observer UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Behavioral/Specification/README.md b/Behavioral/Specification/README.md index 39f0827..1f55b3b 100644 --- a/Behavioral/Specification/README.md +++ b/Behavioral/Specification/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/State/README.md b/Behavioral/State/README.md index 7c4263f..71aff0f 100644 --- a/Behavioral/State/README.md +++ b/Behavioral/State/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/Strategy/README.md b/Behavioral/Strategy/README.md index 88f43dd..9813487 100644 --- a/Behavioral/Strategy/README.md +++ b/Behavioral/Strategy/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/TemplateMethod/README.md b/Behavioral/TemplateMethod/README.md index ce435d2..c01c00c 100644 --- a/Behavioral/TemplateMethod/README.md +++ b/Behavioral/TemplateMethod/README.md @@ -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) \ No newline at end of file diff --git a/Behavioral/Visitor/README.md b/Behavioral/Visitor/README.md index 1ad8cc0..3db1d9c 100644 --- a/Behavioral/Visitor/README.md +++ b/Behavioral/Visitor/README.md @@ -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) \ No newline at end of file diff --git a/Creational/AbstractFactory/README.md b/Creational/AbstractFactory/README.md index aa084fc..34d457d 100644 --- a/Creational/AbstractFactory/README.md +++ b/Creational/AbstractFactory/README.md @@ -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) \ No newline at end of file diff --git a/Creational/Builder/README.md b/Creational/Builder/README.md index 3a85f51..573816a 100644 --- a/Creational/Builder/README.md +++ b/Creational/Builder/README.md @@ -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) \ No newline at end of file diff --git a/Creational/FactoryMethod/README.md b/Creational/FactoryMethod/README.md index 10af7fd..ae4cfb6 100644 --- a/Creational/FactoryMethod/README.md +++ b/Creational/FactoryMethod/README.md @@ -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) \ No newline at end of file diff --git a/Creational/Multiton/README.md b/Creational/Multiton/README.md index 938de9c..26c9a38 100644 --- a/Creational/Multiton/README.md +++ b/Creational/Multiton/README.md @@ -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) \ No newline at end of file diff --git a/Creational/Pool/README.md b/Creational/Pool/README.md index a39c3b2..7229a5a 100644 --- a/Creational/Pool/README.md +++ b/Creational/Pool/README.md @@ -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) \ No newline at end of file diff --git a/Creational/Prototype/README.md b/Creational/Prototype/README.md index 3a99777..80b54ca 100644 --- a/Creational/Prototype/README.md +++ b/Creational/Prototype/README.md @@ -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) \ No newline at end of file diff --git a/Creational/SimpleFactory/README.md b/Creational/SimpleFactory/README.md index c165dc5..fedaa9d 100644 --- a/Creational/SimpleFactory/README.md +++ b/Creational/SimpleFactory/README.md @@ -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) \ No newline at end of file diff --git a/Creational/Singleton/README.md b/Creational/Singleton/README.md index e85703a..5148762 100644 --- a/Creational/Singleton/README.md +++ b/Creational/Singleton/README.md @@ -14,4 +14,8 @@ To have only one instance of this object in the application that will handle all ## Diagram - \ No newline at end of file + + +## UML Diagram + +![Alt Singleton UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Creational/StaticFactory/README.md b/Creational/StaticFactory/README.md index 6c22bc5..f5e2710 100644 --- a/Creational/StaticFactory/README.md +++ b/Creational/StaticFactory/README.md @@ -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) \ No newline at end of file diff --git a/More/Delegation/README.md b/More/Delegation/README.md new file mode 100644 index 0000000..c51128c --- /dev/null +++ b/More/Delegation/README.md @@ -0,0 +1,13 @@ +# Delegation + +## Purpose + +... + +## Examples + +... + +## UML Diagram + +![Alt Delegation UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/More/Delegation/uml/Delegation.uml b/More/Delegation/uml/Delegation.uml new file mode 100644 index 0000000..ffb8e68 --- /dev/null +++ b/More/Delegation/uml/Delegation.uml @@ -0,0 +1,21 @@ + + + PHP + \DesignPatterns\More\Delegation\JuniorDeveloper + + \DesignPatterns\More\Delegation\JuniorDeveloper + \DesignPatterns\More\Delegation\TeamLead + + + + + + + Fields + Constants + Constructors + Methods + + private + + diff --git a/More/Delegation/uml/uml.png b/More/Delegation/uml/uml.png new file mode 100644 index 0000000..f673da2 Binary files /dev/null and b/More/Delegation/uml/uml.png differ diff --git a/More/Delegation/uml/uml.svg b/More/Delegation/uml/uml.svg new file mode 100644 index 0000000..ff49d10 --- /dev/null +++ b/More/Delegation/uml/uml.svg @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + writeBadCode() + + + + + + + + + + + + + JuniorDeveloper + + + JuniorDeveloper + + + + + + + + + + + + + + + + + + + slave + + + + + + + + + + + + + __construct(junior) + + + + + + + + + + + + + writeCode() + + + + + + + + + + + + + TeamLead + + + TeamLead + + + diff --git a/More/Repository/README.md b/More/Repository/README.md index 1c2216f..0e2b188 100644 --- a/More/Repository/README.md +++ b/More/Repository/README.md @@ -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 + +![Alt Repository UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/More/Repository/uml/Repository.uml b/More/Repository/uml/Repository.uml new file mode 100644 index 0000000..e18cfd7 --- /dev/null +++ b/More/Repository/uml/Repository.uml @@ -0,0 +1,28 @@ + + + PHP + \DesignPatterns\Repository\PostRepository + + \DesignPatterns\Repository\Storage + \DesignPatterns\Repository\MemoryStorage + \DesignPatterns\Repository\Post + \DesignPatterns\Repository\PostRepository + + + + + + + + + + + + Fields + Constants + Constructors + Methods + + private + + diff --git a/More/Repository/uml/uml.png b/More/Repository/uml/uml.png new file mode 100644 index 0000000..d22ede8 Binary files /dev/null and b/More/Repository/uml/uml.png differ diff --git a/More/Repository/uml/uml.svg b/More/Repository/uml/uml.svg new file mode 100644 index 0000000..8b9987c --- /dev/null +++ b/More/Repository/uml/uml.svg @@ -0,0 +1,687 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + persist(data) + + + + + + + + + retrieve(id) + + + + + + + + + delete(id) + + + + + + + + + + + + + Storage + + + Storage + + + + + + + + + + + + + + + + + + + data + + + + + + + + + + lastId + + + + + + + + + + + + __construct() + + + + + + + + + + + + persist(data) + + + + + + + + + retrieve(id) + + + + + + + + + delete(id) + + + + + + + + + + + + + MemoryStorage + + + MemoryStorage + + + + + + + + + + + + + + + + + + + id + + + + + + + + + + title + + + + + + + + + + text + + + + + + + + + + author + + + + + + + + + + created + + + + + + + + + + + + setId(id) + + + + + + + + + getId() + + + + + + + + + setAuthor(author) + + + + + + + + + getAuthor() + + + + + + + + + setCreated(created) + + + + + + + + + getCreated() + + + + + + + + + setText(text) + + + + + + + + + getText() + + + + + + + + + setTitle(title) + + + + + + + + + getTitle() + + + + + + + + + + + + + Post + + + Post + + + + + + + + + + + + + + + + + + + persistence + + + + + + + + + + + + __construct(persistence) + + + + + + + + + + + + getById(id) + + + + + + + + + save(post) + + + + + + + + + delete(post) + + + + + + + + + + + + + PostRepository + + + PostRepository + + + + + + + + + diff --git a/More/ServiceLocator/README.md b/More/ServiceLocator/README.md index 199b8cf..cdee496 100644 --- a/More/ServiceLocator/README.md +++ b/More/ServiceLocator/README.md @@ -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 + +![Alt ServiceLocator UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/More/ServiceLocator/uml/ServiceLocator.uml b/More/ServiceLocator/uml/ServiceLocator.uml new file mode 100644 index 0000000..2bfcfb3 --- /dev/null +++ b/More/ServiceLocator/uml/ServiceLocator.uml @@ -0,0 +1,38 @@ + + + PHP + \DesignPatterns\More\ServiceLocator\DatabaseServiceInterface + + \DesignPatterns\More\ServiceLocator\DatabaseServiceInterface + \DesignPatterns\More\ServiceLocator\LogService + \DesignPatterns\More\ServiceLocator\ServiceLocator + \DesignPatterns\More\ServiceLocator\ServiceLocatorInterface + \DesignPatterns\More\ServiceLocator\LogServiceInterface + \DesignPatterns\More\ServiceLocator\DatabaseService + + + + + + + + + + + + + + + + + + + + Fields + Constants + Constructors + Methods + + private + + diff --git a/More/ServiceLocator/uml/uml.png b/More/ServiceLocator/uml/uml.png new file mode 100644 index 0000000..1136eaa Binary files /dev/null and b/More/ServiceLocator/uml/uml.png differ diff --git a/More/ServiceLocator/uml/uml.svg b/More/ServiceLocator/uml/uml.svg new file mode 100644 index 0000000..9ee2d3e --- /dev/null +++ b/More/ServiceLocator/uml/uml.svg @@ -0,0 +1,432 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + DatabaseServiceInterface + + + DatabaseServiceInterface + + + + + + + + + + + + + + + + LogService + + + LogService + + + + + + + + + + + + + + + + + + + services + + + + + + + + + + instantiated + + + + + + + + + + shared + + + + + + + + + + + + __construct() + + + + + + + + + + + + add(interface, service, share) + + + + + + + + + has(interface) + + + + + + + + + get(interface) + + + + + + + + + + + + + ServiceLocator + + + ServiceLocator + + + + + + + + + + + + + + + + + + has(interface) + + + + + + + + + get(interface) + + + + + + + + + + + + + ServiceLocatorInterface + + + ServiceLocatorInterface + + + + + + + + + + + + + + + + LogServiceInterface + + + LogServiceInterface + + + + + + + + + + + + + + + + DatabaseService + + + DatabaseService + + + + + + + + + + + + +