Você está na página 1de 2

Builder Design Pattern:

Builder pattern builds a complex object using simple objects and using a step by step
approach.
This pattern allows a client object to construct a complex object by specifying only its type
and content, being shielded from the details related to the objects representation. This way
the construction process can be used to create different representations. The logic of this
process is isolated form the actual steps used in creating the complex object, so the process
can be used again to create a different object form the same set of simple objects as the
first one.
This type of design pattern comes under creational pattern as this pattern provides one of
the best ways to create an object.A Builder class builds the final object step by step. This
builder is independent of other objects.
The participants classes in this pattern are:

The Builder class specifies an abstract interface for creating parts of a


Product object.

The ConcreteBuilder constructs and puts together parts of the product


by implementing the Builder interface. It defines and keeps track of the representation it
creates and provides an interface for saving the product.

The Director class constructs the complex object using the Builder
interface.

The Product represents the complex object that is being built.

Decorator Design Pattern:


Decorator pattern allows a user to add new functionality to an existing object without altering its
structure. And it can also be used to allow compatibility of obsolete classes with new.
This type of design pattern comes under structural pattern as this pattern acts as a wrapper to
existing class. This pattern creates a decorator class which wraps the original class and provides
additional functionality keeping class methods signature intact.
The participants classes in the decorator pattern are:

Component - Interface for objects that can have responsibilities added to them
dynamically.

ConcreteComponent - Defines an object to which additional responsibilities can be added.

Decorator - Maintains a reference to a Component object and defines an interface that


conforms to Component's interface.

Concrete Decorators - Concrete Decorators extend the functionality of the component by


adding state or adding behavior.

Flyweight design pattern:


Flyweight pattern is primarily used to reduce the number of objects created and to
decrease memory footprint and increase performance. This type of design pattern comes
under structural pattern as this pattern provides ways to decrease object count thus
improving the object structure of application.
Flyweight pattern tries to reuse already existing similar kind objects by storing them and
creates new object when no matching object is found. We will demonstrate this pattern by
drawing 20 circles of different locations but we will create only 5 objects. Only 5 colors are
available so color property is used to check already existing Circle objects.

Mediator design pattern:


The mediator pattern defines an object that encapsulates how a set of objects interact.
This pattern is considered to be a behavioral pattern due to the way it can alter the
program's running behavior.
Usually a program is made up of a large number of classes. So the logic and computation is
distributed among these classes. However, as more classes are developed in a program,
especially during maintenance and/or refactoring, the problem of communication between
these classes may become more complex. This makes the program harder to read and
maintain. Furthermore, it can become difficult to change the program, since any change
may affect code in several other classes.
With the mediator pattern, communication between objects is encapsulated with a
mediator object. Objects no longer communicate directly with each other, but instead
communicate through the mediator. This reduces the dependencies between communicating
objects, thereby lowering the coupling.

Você também pode gostar