A repository of Design Pattern templates
Status:
- (In Progress)
- (
Available
) - (Not Available)
Creational Patterns:
- Handle the creation or clonning of new objects.
- Abstract Factory
- Builder
- Factory Method
- Prototype
- Singleton
Structural Patterns:
- Describes:
- how objects are connected to each other
- how subcclasses and baseclasses interact through
inheritance.
- Relates to the design principles of
decomposition
andgeneralization
.
So, a Structural Pattern describes how classes should work to achieve a particular design goal. (like ingredient in a food to achieve a specific flavor)
Behavioral Patterns:
- Focus on How objects distribute work
- Describe how each object does a single cohesive function
- also Focus on How independent objects work towards a common goal.
So, a a Behavioral Pattern lays out the overall goal and purpose for each object. (like a racing car pit crew in a track)
- Chain of Responsability
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Observer
- [State]
- Strategy
- Template method
- Visitor
- Purpose:
- Provides communication between two existing classes (
ClientClass
andAdapteeClass
) by providing a compatible interfaceTargetInterface
. - When a pre-existing software (
ClientClass
) needs to use third-party libraries (AdapteeClass
) or needs to connect to a external sw/hw.
- Provides communication between two existing classes (
- Parts:
ClientClass
: Class which is part of your software and wants to use third-party libraries or external sw/hw.AdapteeClass
: This is the third-party class or external sw/hw.AdapterClass
:- It is what the
ClientClass
expects. It implements theTargetInterface
. - It traslates the
ClientClass
requests into a message that theAdapteeClass
can understand.
- It is what the
TargetInterface
: It is used by theClientClass
to send a request to the adapter,
- Steps:
- Design the
TargetInterface
- Implements the
AdapterClass
- Send the request from the
ClientClass
to theAdapterClass
using theTargetInterface
- Design the
- LINK to Repository Project: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Provides a single, simplified
interface
forClientClasses
to interact with a subsystem. - If there is a need for a class to instantiate other classes within your system and to provide these instances to another class.
- Provides a single, simplified
- Parts:
ICommonFunctionalities
: defines the methods which are common to all the classes to be refactored/created.FaçadeClass
:- It is a wrapper class that encapsulates a subsystem and hides its complexity.
- It uses
aggregation
.
- It uses
- It allows the
ClientClass
to interact with the subsystem though afaçade
.
- It is a wrapper class that encapsulates a subsystem and hides its complexity.
ClientClass
: Calls the methods defined inICommonFunctionalities
and implemented in the differentClass1
,Class2
andCSlass3
using only theFaçadeClass
- Steps:
- Design the
interface
extracting common methods to be used by theClientClass
- Implement the
interface
with one or more classes - Create the
FaçadeClass
and wrap the classes that implement theinterface
- Use the
FaçadeClass
to access the subsystem. - Implement the
ClientClass
to call the methods of the subsystem through theFaçadeClass
.
- Design the
- LINK to Repository Project: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose: A Finite State Machine on steroids.
- Finite State Machine:
- A class with an
enum
which represents thestates
- The constructor will set the initial state.
- A main function has a while loop which call different methods according to the current object state.
- Each
state
has a method associated. The output of this methods will change the state to another one. - LINK to FSM Repository Project: Here
- A class with an
- Finite State Machine:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- To define a family of encapsulated and interchangeable algorithms, i.e. they are
client
independent. Each algorithm is called ofstrategy
. - to use different variants of an algorithm within an object and be able to switch from one algorithm to another during runtime .
- to isolate the business logic of a class from the implementation details of algorithms that may not be as important in the context of that logic
- To replace an humongous, general and plenty-of-conditionals main algorithm.
- To define a family of encapsulated and interchangeable algorithms, i.e. they are
- Parts:
ContextClass
- It has a reference to a
Strategy
object- It calls the
Strategy
methods through the interface
- It calls the
- It has a reference to a
- It has a setter to change the
strategy
object at runtime - It does not know
- what type of strategy it works with
- how the algorithm is executed
IStrategy
:- It defines a common
interface
for all the algorithms. - It is used by the
ContextClass
to call aConcreteStrategy
- It defines a common
ConcreteStrategy1
, ...ConcreteStrategyN
: Implements an algorithm using theIStrategy
interface.ClientClass
:- Creates the strategy object and passes it to the
ContextClass
- It can change the
Strategy
object of the context class at runtime.
- Creates the strategy object and passes it to the
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here
- Purpose:
- Parts:
- Steps:
- LINK: Here