diff --git a/Behavioral/ChainOfResponsibilities/README.md b/Behavioral/ChainOfResponsibilities/README.md deleted file mode 100644 index 7657e93be..000000000 --- a/Behavioral/ChainOfResponsibilities/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Chain Of Responsibilities - -## Purpose: - -To build a chain of objects to handle a call in sequential order. If one object cannot handle a call, it delegates the call to the next in the chain and so forth. - -## Examples: - -* logging framework, where each chain element decides autonomously what to do with a log message -* 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) diff --git a/Behavioral/ChainOfResponsibilities/index.rst b/Behavioral/ChainOfResponsibilities/README.rst similarity index 100% rename from Behavioral/ChainOfResponsibilities/index.rst rename to Behavioral/ChainOfResponsibilities/README.rst diff --git a/Behavioral/Command/README.md b/Behavioral/Command/README.md deleted file mode 100644 index adf2de306..000000000 --- a/Behavioral/Command/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Command - -## Purpose - -To encapsulate invocation and decoupling. - -We have an Invoker and a Receiver. This pattern uses a "Command" to delegate the method call against the Receiver and presents the same method "execute". -Therefore, the Invoker just knows to call "execute" to process the Command of the client. The Receiver is decoupled from the Invoker. - -The second aspect of this pattern is the undo(), which undoes the method execute(). -Command can also be aggregated to combine more complex commands with minimum copy-paste and relying on composition over inheritance. - -## Examples - -* 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/Command/index.rst b/Behavioral/Command/README.rst similarity index 100% rename from Behavioral/Command/index.rst rename to Behavioral/Command/README.rst diff --git a/Behavioral/Iterator/README.md b/Behavioral/Iterator/README.md deleted file mode 100644 index 46e96b8b5..000000000 --- a/Behavioral/Iterator/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Iterator - -## Purpose - -To make an object iterable and to make it appear like a collection of objects. - -## Examples - -* to process a file line by line by just running over all lines (which have an object representation) for a file (which of course is an object, too) - -## 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/Iterator/index.rst b/Behavioral/Iterator/README.rst similarity index 100% rename from Behavioral/Iterator/index.rst rename to Behavioral/Iterator/README.rst diff --git a/Behavioral/Mediator/README.md b/Behavioral/Mediator/README.md deleted file mode 100644 index 818ff4cc1..000000000 --- a/Behavioral/Mediator/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Mediator - -## Purpose - -This pattern provides an easy to decouple many components working together. -It is a good alternative over Observer IF you have a "central intelligence", -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/Mediator/index.rst b/Behavioral/Mediator/README.rst similarity index 100% rename from Behavioral/Mediator/index.rst rename to Behavioral/Mediator/README.rst diff --git a/Behavioral/Memento/README.md b/Behavioral/Memento/README.md deleted file mode 100644 index 4e3294e69..000000000 --- a/Behavioral/Memento/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Memento - -## Purpose - -Provide the ability to restore an object to its previous state (undo via rollback). - -The memento pattern is implemented with three objects: the originator, a caretaker and a memento. -The originator is some object that has an internal state. -The caretaker is going to do something to the originator, but wants to be able to undo the change. -The caretaker first asks the originator for a memento object. Then it does whatever operation (or sequence of operations) it was going to do. -To roll back to the state before the operations, it returns the memento object to the originator. -The memento object itself is an opaque object (one which the caretaker cannot, or should not, change). -When using this pattern, care should be taken if the originator may change other objects or resources - the memento pattern operates on a single object. - -## Examples - -* 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/Memento/index.rst b/Behavioral/Memento/README.rst similarity index 100% rename from Behavioral/Memento/index.rst rename to Behavioral/Memento/README.rst diff --git a/Behavioral/NullObject/README.md b/Behavioral/NullObject/README.md deleted file mode 100644 index 108b07cf1..000000000 --- a/Behavioral/NullObject/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Null Object - -## Purpose - -NullObject is not a GoF design pattern but a schema which appears frequently enough to be considered a pattern. It has the following benefits: - -* Client code is simplified -* Reduces the chance of null pointer exceptions -* Fewer conditionals require less test cases - -Methods that return an object or null should instead return an object or `NullObject`. `NullObject`s simplify boilerplate code such as `if (!is_null($obj)) { $obj->callSomething(); }` to just `$obj->callSomething();` by eliminating the conditional check in client code. - -## Examples - -* Symfony2: null logger of profiler -* 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) diff --git a/Behavioral/NullObject/index.rst b/Behavioral/NullObject/README.rst similarity index 100% rename from Behavioral/NullObject/index.rst rename to Behavioral/NullObject/README.rst diff --git a/Behavioral/Observer/README.md b/Behavioral/Observer/README.md deleted file mode 100644 index ccaeaca5a..000000000 --- a/Behavioral/Observer/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Observer - -## Purpose - -To implement a publish/subscribe behaviour to an object, whenever a "Subject" object changes it's state, the attached -"Observers" will be notified. It is used to shorten the amount of coupled objects and uses loose coupling instead. - -## Examples - -* a message queue system is observed to show the progress of a job in a GUI - -## Note - -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/Observer/index.rst b/Behavioral/Observer/README.rst similarity index 100% rename from Behavioral/Observer/index.rst rename to Behavioral/Observer/README.rst diff --git a/Behavioral/index.rst b/Behavioral/README.rst similarity index 54% rename from Behavioral/index.rst rename to Behavioral/README.rst index 3513745f4..afd911c9c 100644 --- a/Behavioral/index.rst +++ b/Behavioral/README.rst @@ -9,15 +9,15 @@ carrying out this communication. .. toctree:: :titlesonly: - ChainOfResponsibilities/index - Command/index - Iterator/index - Mediator/index - Memento/index - NullObject/index - Observer/index - Specification/index - State/index - Strategy/index - TemplateMethod/index - Visitor/index \ No newline at end of file + ChainOfResponsibilities/README + Command/README + Iterator/README + Mediator/README + Memento/README + NullObject/README + Observer/README + Specification/README + State/README + Strategy/README + TemplateMethod/README + Visitor/README \ No newline at end of file diff --git a/Behavioral/Specification/README.md b/Behavioral/Specification/README.md deleted file mode 100644 index 1f55b3b08..000000000 --- a/Behavioral/Specification/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Specification - -## Purpose - -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/Specification/index.rst b/Behavioral/Specification/README.rst similarity index 100% rename from Behavioral/Specification/index.rst rename to Behavioral/Specification/README.rst diff --git a/Behavioral/State/README.md b/Behavioral/State/README.md deleted file mode 100644 index 71aff0f3e..000000000 --- a/Behavioral/State/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# State - -## 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/State/index.rst b/Behavioral/State/README.rst similarity index 100% rename from Behavioral/State/index.rst rename to Behavioral/State/README.rst diff --git a/Behavioral/Strategy/README.md b/Behavioral/Strategy/README.md deleted file mode 100644 index 98134877d..000000000 --- a/Behavioral/Strategy/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Strategy - -## Terminology: - -* Context -* Strategy -* Concrete Strategy - -## Purpose - -To separate strategies and to enable fast switching between them. Also this pattern is a good alternative to inheritance (instead of having an abstract class that is extended). - -## Examples - -* 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/Strategy/index.rst b/Behavioral/Strategy/README.rst similarity index 100% rename from Behavioral/Strategy/index.rst rename to Behavioral/Strategy/README.rst diff --git a/Behavioral/TemplateMethod/README.md b/Behavioral/TemplateMethod/README.md deleted file mode 100644 index c01c00cb1..000000000 --- a/Behavioral/TemplateMethod/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Template Method - -## Purpose - -Template Method is a behavioral design pattern. - -Perhaps you have encountered it many times already. The idea is to let subclasses of this abstract template "finish" the behavior of an algorithm. - -A.k.a the "Hollywood principle": "Don't call us, we call you." This class is not called by subclasses but the inverse. -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/TemplateMethod/index.rst b/Behavioral/TemplateMethod/README.rst similarity index 100% rename from Behavioral/TemplateMethod/index.rst rename to Behavioral/TemplateMethod/README.rst diff --git a/Behavioral/Visitor/README.md b/Behavioral/Visitor/README.md deleted file mode 100644 index 3db1d9c25..000000000 --- a/Behavioral/Visitor/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Visitor - -## Purpose - -The Visitor Pattern lets you outsource operations on objects to other objects. The main reason to do this is to keep a separation of concerns. -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/Behavioral/Visitor/index.rst b/Behavioral/Visitor/README.rst similarity index 100% rename from Behavioral/Visitor/index.rst rename to Behavioral/Visitor/README.rst diff --git a/Creational/AbstractFactory/README.md b/Creational/AbstractFactory/README.md deleted file mode 100644 index 34d457d15..000000000 --- a/Creational/AbstractFactory/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Abstract Factory - -## Purpose - -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/AbstractFactory/index.rst b/Creational/AbstractFactory/README.rst similarity index 100% rename from Creational/AbstractFactory/index.rst rename to Creational/AbstractFactory/README.rst diff --git a/Creational/Builder/Parts/README.md b/Creational/Builder/Parts/README.md deleted file mode 100644 index 9e802c8c1..000000000 --- a/Creational/Builder/Parts/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# - -# Purpose - - - -# Examples - -* - diff --git a/Creational/Builder/README.md b/Creational/Builder/README.md deleted file mode 100644 index 573816a96..000000000 --- a/Creational/Builder/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Builder - -## Purpose - -Builder is an interface that build parts of a complex object. - -Sometimes, if the builder has a better knowledge of what it builds, this interface could be an abstract class with default methods (aka adapter). - -If you have a complex inheritance tree for objects, it is logical to have a complex inheritance tree for builders too. - -Note: Builders have often a fluent interface, see the mock builder of PHPUnit for example. - -## Examples - -* PHPUnit: Mock Builder - -## UML Diagram - -![Alt Builder UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Creational/Builder/index.rst b/Creational/Builder/README.rst similarity index 100% rename from Creational/Builder/index.rst rename to Creational/Builder/README.rst diff --git a/Creational/FactoryMethod/README.md b/Creational/FactoryMethod/README.md deleted file mode 100644 index ae4cfb627..000000000 --- a/Creational/FactoryMethod/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Factory Method - -## Purpose - -The good point over the SimpleFactory is you can subclass it to implement different ways to create objects - -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/FactoryMethod/index.rst b/Creational/FactoryMethod/README.rst similarity index 100% rename from Creational/FactoryMethod/index.rst rename to Creational/FactoryMethod/README.rst diff --git a/Creational/Multiton/README.md b/Creational/Multiton/README.md deleted file mode 100644 index 26c9a386d..000000000 --- a/Creational/Multiton/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Multiton - -**THIS IS CONSIDERED TO BE AN ANTI-PATTERN! FOR BETTER TESTABILITY AND MAINTAINABILITY USE DEPENDENCY INJECTION!** - -# Purpose - -To have only a list of named instances that are used, like a singleton but with n instances. - -# Examples - -* 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/Multiton/index.rst b/Creational/Multiton/README.rst similarity index 100% rename from Creational/Multiton/index.rst rename to Creational/Multiton/README.rst diff --git a/Creational/Pool/README.md b/Creational/Pool/README.md deleted file mode 100644 index 7229a5a55..000000000 --- a/Creational/Pool/README.md +++ /dev/null @@ -1,12 +0,0 @@ -Pool -==== - -The **object pool pattern** is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand. A client of the pool will request an object from the pool and perform operations on the returned object. When the client has finished, it returns the object, which is a specific type of factory object, to the pool rather than destroying it. - -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/Pool/index.rst b/Creational/Pool/README.rst similarity index 100% rename from Creational/Pool/index.rst rename to Creational/Pool/README.rst diff --git a/Creational/Prototype/README.md b/Creational/Prototype/README.md deleted file mode 100644 index 6244e8a74..000000000 --- a/Creational/Prototype/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Prototype - -## Purpose - -To avoid the cost of creating objects the standard way (new Foo()) and instead create a prototype and clone it. - -## 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) diff --git a/Creational/Prototype/index.rst b/Creational/Prototype/README.rst similarity index 100% rename from Creational/Prototype/index.rst rename to Creational/Prototype/README.rst diff --git a/Creational/index.rst b/Creational/README.rst similarity index 69% rename from Creational/index.rst rename to Creational/README.rst index 6d041a7b6..72eb5d37b 100644 --- a/Creational/index.rst +++ b/Creational/README.rst @@ -11,12 +11,12 @@ this object creation. .. toctree:: :titlesonly: - AbstractFactory/index - Builder/index - FactoryMethod/index - Multiton/index - Pool/index - Prototype/index - SimpleFactory/index - Singleton/index - StaticFactory/index \ No newline at end of file + AbstractFactory/README + Builder/README + FactoryMethod/README + Multiton/README + Pool/README + Prototype/README + SimpleFactory/README + Singleton/README + StaticFactory/README \ No newline at end of file diff --git a/Creational/SimpleFactory/README.md b/Creational/SimpleFactory/README.md deleted file mode 100644 index fedaa9dac..000000000 --- a/Creational/SimpleFactory/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Simple Factory - -## Purpose - -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/SimpleFactory/index.rst b/Creational/SimpleFactory/README.rst similarity index 100% rename from Creational/SimpleFactory/index.rst rename to Creational/SimpleFactory/README.rst diff --git a/Creational/Singleton/README.md b/Creational/Singleton/README.md deleted file mode 100644 index b90fcdce8..000000000 --- a/Creational/Singleton/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Singleton - -**THIS IS CONSIDERED TO BE AN ANTI-PATTERN! FOR BETTER TESTABILITY AND MAINTAINABILITY USE DEPENDENCY INJECTION!** - -## Purpose - -To have only one instance of this object in the application that will handle all calls. - -## Examples - -* DB Connector -* Logger (may also be a Multiton if there are many log files for several purposes) -* Lock file for the application (there is only one in the filesystem ...) - -## UML Diagram - -![Alt Singleton UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Creational/Singleton/index.rst b/Creational/Singleton/README.rst similarity index 100% rename from Creational/Singleton/index.rst rename to Creational/Singleton/README.rst diff --git a/Creational/StaticFactory/README.md b/Creational/StaticFactory/README.md deleted file mode 100644 index f5e27104f..000000000 --- a/Creational/StaticFactory/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Static Factory - -## Purpose - -Similar to the AbstractFactory, this pattern is used to create series of related or dependent objects. -The difference between this and the abstract factory pattern is that the static factory pattern uses just one static -method to create all types of objects it can create. It is usually named `factory` or `build`. - -## 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/Creational/StaticFactory/index.rst b/Creational/StaticFactory/README.rst similarity index 100% rename from Creational/StaticFactory/index.rst rename to Creational/StaticFactory/README.rst diff --git a/More/Delegation/README.md b/More/Delegation/README.md deleted file mode 100644 index c51128ced..000000000 --- a/More/Delegation/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Delegation - -## Purpose - -... - -## Examples - -... - -## UML Diagram - -![Alt Delegation UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/More/Delegation/index.rst b/More/Delegation/README.rst similarity index 100% rename from More/Delegation/index.rst rename to More/Delegation/README.rst diff --git a/More/README.rst b/More/README.rst new file mode 100644 index 000000000..b0550f27c --- /dev/null +++ b/More/README.rst @@ -0,0 +1,9 @@ +More +==== + +.. toctree:: + :titlesonly: + + Delegation/README + ServiceLocator/README + Repository/README \ No newline at end of file diff --git a/More/Repository/README.md b/More/Repository/README.md deleted file mode 100644 index 0e2b188ad..000000000 --- a/More/Repository/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Repository - -## Purpose - -Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects. -Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. -Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers. - -## Examples - -* 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/index.rst b/More/Repository/README.rst similarity index 100% rename from More/Repository/index.rst rename to More/Repository/README.rst diff --git a/More/ServiceLocator/README.md b/More/ServiceLocator/README.md deleted file mode 100644 index cdee49629..000000000 --- a/More/ServiceLocator/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Service Locator - -## Purpose - -To implement a loosely coupled architecture in order to get better testable, maintainable and extendable code. -DI pattern and Service Locator pattern are an implementation of the Inverse of Control pattern. - -## Usage - -With `ServiceLocator` you can register a service for a given interface. By using the interface you can retrieve the service -and use it in the classes of the application without knowing its implementation. You can configure and inject the -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/index.rst b/More/ServiceLocator/README.rst similarity index 100% rename from More/ServiceLocator/index.rst rename to More/ServiceLocator/README.rst diff --git a/More/index.rst b/More/index.rst deleted file mode 100644 index 6ba85d3be..000000000 --- a/More/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -More -==== - -.. toctree:: - :titlesonly: - - Delegation/index - ServiceLocator/index - Repository/index \ No newline at end of file diff --git a/index.rst b/README.rst similarity index 97% rename from index.rst rename to README.rst index fbda3c9fe..cf83385ec 100644 --- a/index.rst +++ b/README.rst @@ -26,10 +26,10 @@ Please click on **the title of every pattern's page** for a full explanation of :titlesonly: :numbered: - Creational/index - Structural/index - Behavioral/index - More/index + Creational/README + Structural/README + Behavioral/README + More/README Contribute ---------- diff --git a/Structural/Adapter/README.md b/Structural/Adapter/README.md deleted file mode 100644 index d2390dfa7..000000000 --- a/Structural/Adapter/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Adapter / Wrapper - -## Purpose - -To translate one interface for a class into a compatible interface. An adapter allows classes to work together that normally could not because of incompatible interfaces by providing it's interface to clients while using the original interface. - -## Examples - -* DB Client libraries adapter -* using multiple different webservices and adapters normalize data so that the outcome is the same for all - -## UML Diagram - -![Alt Adapter UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Structural/Adapter/index.rst b/Structural/Adapter/README.rst similarity index 100% rename from Structural/Adapter/index.rst rename to Structural/Adapter/README.rst diff --git a/Structural/Bridge/README.md b/Structural/Bridge/README.md deleted file mode 100644 index b4bf4fd43..000000000 --- a/Structural/Bridge/README.md +++ /dev/null @@ -1,12 +0,0 @@ -## Purpose - -Decouple an abstraction from its implementation so that the two can vary -independently. (http://en.wikipedia.org/wiki/Bridge_pattern) - -#### Sample: - -* [Symfony DoctrineBridge](https://github.com/symfony/DoctrineBridge) - -## UML Diagram - -![Alt Bridge UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Structural/Bridge/index.rst b/Structural/Bridge/README.rst similarity index 100% rename from Structural/Bridge/index.rst rename to Structural/Bridge/README.rst diff --git a/Structural/Composite/README.md b/Structural/Composite/README.md deleted file mode 100755 index f0ca01c3c..000000000 --- a/Structural/Composite/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Composite - -# Purpose - -To treat a group of objects the same way as a single instance of the object. - -# Examples - -* a form class instance handles all its form elements like a single instance of the form, when `render()` is called, it - subsequently runs through all its child elements and calls `render()` on them -* `Zend_Config`: a tree of configuration options, each one is a `Zend_Config` object itself - -## UML Diagram - -![Alt Composite UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Structural/Composite/index.rst b/Structural/Composite/README.rst similarity index 100% rename from Structural/Composite/index.rst rename to Structural/Composite/README.rst diff --git a/Structural/DataMapper/README.md b/Structural/DataMapper/README.md deleted file mode 100644 index 70efe20f6..000000000 --- a/Structural/DataMapper/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Data Mapper - -## Purpose - -A Data Mapper, is a Data Access Layer that performs bidirectional transfer of -data between a persistent data store (often a relational database) and an in -memory data representation (the domain layer). The goal of the pattern is to -keep the in memory representation and the persistent data store independent of -each other and the data mapper itself. The layer is composed of one or more -mappers (or Data Access Objects), performing the data transfer. Mapper -implementations vary in scope. Generic mappers will handle many different domain -entity types, dedicated mappers will handle one or a few. - -The key point of this pattern is, unlike Active Record pattern, the data model follows Single Responsibility Principle. - -## Examples - -* DB Object Relational Mapper (ORM) : Doctrine2 uses DAO named as "EntityRepository" - -## UML Diagram - -![Alt DataMapper UML Diagram](uml/uml.png) diff --git a/Structural/DataMapper/index.rst b/Structural/DataMapper/README.rst similarity index 100% rename from Structural/DataMapper/index.rst rename to Structural/DataMapper/README.rst diff --git a/Structural/Decorator/README.md b/Structural/Decorator/README.md deleted file mode 100644 index 4eedd898d..000000000 --- a/Structural/Decorator/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Decorator - -## Purpose - -To dynamically add new functionality to class instances. - -## Examples - -* Zend Framework: decorators for `Zend_Form_Element` instances -* Web Service Layer: Decorators JSON and XML for a REST service (in this case, only one of these should be allowed of course) - -## UML Diagram - -![Alt Decorator UML Diagram](uml/uml.png) diff --git a/Structural/Decorator/index.rst b/Structural/Decorator/README.rst similarity index 100% rename from Structural/Decorator/index.rst rename to Structural/Decorator/README.rst diff --git a/Structural/DependencyInjection/README.md b/Structural/DependencyInjection/README.md deleted file mode 100644 index 185a550e6..000000000 --- a/Structural/DependencyInjection/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Dependency Injection - -## Purpose - -To implement a loosely coupled architecture in order to get better testable, maintainable and extendable code. - -## Usage - -Configuration gets injected and `Connection` will get all that it needs from `$config`. Without DI, the configuration would be created directly in `Connection`, which is not very good for testing and extending `Connection`. - -Notice we are following Inversion of control principle in `Connection` by asking `$config` to implement `Parameters` interface. This decouples our components. We don't care where the source of information comes from, we only care that `$config` has certain methods to retrieve that information. Read more about Inversion of control [here](http://en.wikipedia.org/wiki/Inversion_of_control). - -## Examples - -* The Doctrine2 ORM uses dependency injection e.g. for configuration that is injected into a `Connection` object. For testing purposes, one can easily create a mock object of the configuration and inject that into the `Connection` object -* Symfony and Zend Framework 2 already have containers for DI that create objects via a configuration array and inject them where needed (i.e. in Controllers) - -## UML Diagram - -![Alt DependencyInjection UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Structural/DependencyInjection/index.rst b/Structural/DependencyInjection/README.rst similarity index 100% rename from Structural/DependencyInjection/index.rst rename to Structural/DependencyInjection/README.rst diff --git a/Structural/Facade/README.md b/Structural/Facade/README.md deleted file mode 100644 index 4a9019cea..000000000 --- a/Structural/Facade/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Facade - -## Purpose - -The primary goal of a Facade Pattern is not to avoid you to read the manual of a complex API. It's only a side-effect. -The first goal is to reduce coupling and follow the Law of Demeter. - -A Facade is meant to decouple a client and a sub-system by embedding many (but sometimes just one) interface, and of course to reduce complexity. - -* A facade does not forbid you the access to the sub-system -* You can (you should) have multiple facades for one sub-system - -That's why a good facade has no `new` in it. If there are multiple creations for each method, it is not a Facade, it's a Builder or a -[Abstract|Static|Simple] Factory [Method]. - -The best facade has no `new` and a constructor with interface-type-hinted parameters. -If you need creation of new instances, use a Factory as argument. - -## UML Diagram - -![Alt Facade UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Structural/Facade/index.rst b/Structural/Facade/README.rst similarity index 100% rename from Structural/Facade/index.rst rename to Structural/Facade/README.rst diff --git a/Structural/FluentInterface/README.md b/Structural/FluentInterface/README.md deleted file mode 100644 index 2ed92d3d1..000000000 --- a/Structural/FluentInterface/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Fluent Interface - -## Purpose - -To write code that is easy readable just like sentences in a natural language (like English). - -## Examples - -* Doctrine2's QueryBuilder works something like that example class below -* PHPUnit uses fluent interfaces to build mock objects -* Yii Framework: CDbCommand and CActiveRecord use this pattern, too - -## UML Diagram - -![Alt FluentInterface UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Structural/FluentInterface/index.rst b/Structural/FluentInterface/README.rst similarity index 100% rename from Structural/FluentInterface/index.rst rename to Structural/FluentInterface/README.rst diff --git a/Structural/Proxy/README.md b/Structural/Proxy/README.md deleted file mode 100644 index b4c0e3920..000000000 --- a/Structural/Proxy/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Proxy - -## Purpose - -To interface to anything that is expensive or impossible to duplicate. - -## Examples - -* Doctrine2 uses proxies to implement framework magic (e.g. lazy initialization) in them, while the user still works with his own entity classes and will never use nor touch the proxies - -## UML Diagram - -![Alt Proxy UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Structural/Proxy/index.rst b/Structural/Proxy/README.rst similarity index 100% rename from Structural/Proxy/index.rst rename to Structural/Proxy/README.rst diff --git a/Structural/index.rst b/Structural/README.rst similarity index 51% rename from Structural/index.rst rename to Structural/README.rst index 65054139a..47b665036 100644 --- a/Structural/index.rst +++ b/Structural/README.rst @@ -8,13 +8,13 @@ relationships between entities. .. toctree:: :titlesonly: - Adapter/index - Bridge/index - Composite/index - DataMapper/index - Decorator/index - DependencyInjection/index - Facade/index - FluentInterface/index - Proxy/index - Registry/index \ No newline at end of file + Adapter/README + Bridge/README + Composite/README + DataMapper/README + Decorator/README + DependencyInjection/README + Facade/README + FluentInterface/README + Proxy/README + Registry/README \ No newline at end of file diff --git a/Structural/Registry/README.md b/Structural/Registry/README.md deleted file mode 100644 index 840d2cf96..000000000 --- a/Structural/Registry/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Registry - -## Purpose - -To implement a central storage for objects often used throughout the application, is typically implemented using -an abstract class with only static methods (or using the Singleton pattern) - -## Examples - -* Zend Framework: `Zend_Registry` holds the application's logger object, front controller etc. -* Yii Framework: `CWebApplication` holds all the application components, such as `CWebUser`, `CUrlManager`, etc. - -## UML Diagram - -![Alt Registry UML Diagram](uml/uml.png) \ No newline at end of file diff --git a/Structural/Registry/index.rst b/Structural/Registry/README.rst similarity index 100% rename from Structural/Registry/index.rst rename to Structural/Registry/README.rst diff --git a/conf.py b/conf.py index 5ae01ae91..6df45f4e9 100644 --- a/conf.py +++ b/conf.py @@ -43,7 +43,7 @@ #source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = 'README' # General information about the project. project = u'DesignPatternsPHP' diff --git a/read-the-docs.sh b/read-the-docs.sh deleted file mode 100755 index e868670cc..000000000 --- a/read-the-docs.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -# Step 1 use pandoc to convert README.md to index.rst -find . -type f -name "README.md" \ - -execdir pandoc -f markdown -t rst -s -o "index.rst" {} \; \ -# -delete - -# Step 2 move uml/* of every pattern to images/path_to_pattern/uml/* -#find . -type d -name "uml" \ -# -exec bash -c 'mkdir -p images/${1:2}' funcname {} \; \ -# -exec bash -c 'mv ${1}/* images/${1:2}' funcname {} \; \ -# -delete - -# Step 3 change the content of index.rst -# embed php files in index.rst -for INDEX in $(find . -type f -name "index.rst") -do - # fix figure to image, add align center - sed -i "s|.. figure::|.. image::|g" ${INDEX} - sed -i "/:alt:/{n;d}" ${INDEX} - sed -i "s| Alt.*| :align: center|" ${INDEX} - - BASEDIR=$(dirname ${INDEX}) - - # fix image path uml/uml.png to images/path_to_pattern/uml/uml.png - # sed -i "s|uml/uml.png|/images/${BASEDIR:2}/uml/uml.png|g" ${INDEX} - - # embed pattern files - echo -e "\nCode\n----\n" >> ${INDEX} - echo -e "You can also find these code on \`GitHub\`_\n" >> ${INDEX} - - for PHPFILE in $(find ${BASEDIR} -maxdepth 1 -type f -name "*.php") - do - echo -e "$(basename ${PHPFILE})\n" >> ${INDEX} - echo -e ".. literalinclude:: $(basename ${PHPFILE})\n :language: php\n :linenos:\n" >> ${INDEX} - done - - # embed test files - echo -e "Test\n----\n" >> ${INDEX} - - for TESTFILE in $(find ${BASEDIR}/Tests -maxdepth 1 -type f -name "*.php") - do - echo -e "Tests/$(basename ${TESTFILE})\n" >> ${INDEX} - echo -e ".. literalinclude:: Tests/$(basename ${TESTFILE})\n :language: php\n :linenos:\n" >> ${INDEX} - done - - # add link on GitHub of this pattern - echo -e ".. _\`GitHub\`: https://github.com/domnikl/DesignPatternsPHP/tree/master/${BASEDIR:2}" >> ${INDEX} -done - -# Step 4 embed other php files in index.rst -# fix TocTree of projet \ No newline at end of file