Design pattern for chess masters
Today I played chess with a colleague, I made a couple of very good forks.
But he put me in trouble with a good opening.
Do you know what openings, forks and also nailing are in chess?
They are very precise schemes, they have the names (Gambetto di donna, Sicilian defense, English match, French defense,…), well-defined patterns, every good chess player must know in memory.
These chess pattern are grouped into different families like opening, finals, and so on.
They are very precise moves, which you can always repeat, in every game or several times in a game, to which names have been assigned and they bring a very precise benefits.
So, what tactics are for chess, then Design pattern are for OO Design:
- a general design solution
- to a repeatable situation
- with a description
- a very precise schema
- and that you have to know
- grouped in different families: creational, structural and behavioral
The general design situation means that, when you are designing an object oriented software, there is a well know way to do it for each type of component and layer.
Repeatable means that the situations are the same for each system you can design and so you can use again that model
With a description means that that situation has a name
Very precise schema means that there is a design model already ready to use and that you could adapt it to your component
You have to know means that you should study them so that you can apply in every situation
The different families are about the different type of design situations
- Creational are abut the way in which objects are created
- Structural pattern identify a simple way to realize relationships among entities
- Behavioral provide solution for the better interaction between objects
Example of Creational pattern:
- Abstract Factory pattern: a class requests the objects it requires from a factory object instead of creating the objects directly
- Factory method pattern: centralize creation of an object of a specific type choosing one of several implementations
- Builder pattern: separate the construction of a complex object from its representation so that the same construction process can create different representations
- Dependency Injection pattern: a class accepts the objects it requires from an injector instead of creating the objects directly
- Lazy initialization pattern: tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed
- Object pool pattern: avoid expensive acquisition and release of resources by recycling objects that are no longer in use
- Prototype pattern: used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects
- Singleton pattern: restrict instantiation of a class to one object
Example of Structural pattern:
- Adapter pattern: ‘adapts’ one interface for a class into one that a client expects
- Bridge pattern: decouple an abstraction from its implementation so that the two can vary independently
- Composite pattern: a tree structure of objects where every object has the same interface
- Decorator pattern: add additional functionality to a class at runtime where subclassing would result in an exponential rise of new classes
- Extensibility pattern: a.k.a. Framework – hide complex code behind a simple interface
- Facade pattern: create a simplified interface of an existing interface to ease usage for common tasks
- Flyweight pattern: a large quantity of objects share a common properties object to save space
- Pipes and filters: a chain of processes where the output of each process is the input of the next
- Proxy pattern: a class functioning as an interface to another thing
Example of Behavioral pattern:
- Chain of responsibility pattern: Command objects are handled or passed on to other objects by logic-containing processing objects
- Command pattern: Command objects encapsulate an action and its parameters
- Interpreter pattern: Implement a specialized computer language to rapidly solve a specific set of problems
- Iterator pattern: Iterators are used to access the elements of an aggregate object sequentially without exposing its underlying representation
- Mediator pattern: Provides a unified interface to a set of interfaces in a subsystem
- Memento pattern: Provides the ability to restore an object to its previous state (rollback)
- Null object pattern: Designed to act as a default value of an object
- Observer pattern: a.k.a. Publish/Subscribe or Event Listener. Objects register to observe an event that may be raised by another object
- State pattern: A clean way for an object to partially change its type at runtime
- Strategy pattern: Algorithms can be selected on the fly, using composition
- Template method pattern: Describes the program skeleton of a program; algorithms can be selected on the fly, using inheritance
- Visitor pattern: A way to separate an algorithm from an object