Design Patterns Part 2

June 1, 2020

Part 1, 2, 3


Builder

The Builder pattern as being used to separate the construction of a complex object from its representation so that the same construction process can create different representations.

Gang of Four

it’s just a pattern that lets you separate and reuse a specific process to build something, like constructing an object. You’ll only want to do this when the construction process is complex. Otherwise, there’s really no need to do this and it’ll be an overkill.

The builder pattern is pretty similar to the abstract factory, but the abstract factory works more with a family of objects, whether or not they are simple or complex. However, the builder pattern focuses on constructing one product that’s a complex object, step by step.

Adapter

Defines the intent of an adapter pattern to be to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

Gang of Four

Essentially it is to make incompatible interfaces compatible by making it possible for them to work together.

Composite

Is to compose objects into tree structures to represent part-whole hierarchies. The composite pattern lets clients treat individual objects and compositions of objects uniformly.

Gang of Four

Essentially, it’s all about treating a group of objects and a single object as the same, while they can be different. 

The component interface declares an interface of objects in the composition, and it also implements default behavior for the interface common to all classes, as appropriate. It also declares an interface for accessing and managing it’s child components. 

The leaf that represents the leaf objects in the composition. A leaf has no children. Composite defines behavior for components having children. They can also store child components and implement child-related operations in the component interface.

Sample

Chain of Responsibility

Its intent is to avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Also, it has the intent to chain the receiving objects and pass the request along the chain until an object handles it.

Gang of Four

In real life, if you’ve ever called a help desk, you might get first support to help troubleshoot a problem and if they can’t handle it, they might pass it on to second-level support. And if they can’t handle it, then third-level support. That’s a form of a chain of responsibility right there

Sample

Command

The intent for the Command Pattern is to encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

Gang of Four

The command pattern uses an object to store required information to perform an action at any point in time, that can later be undone.

Sample

Interpreter

Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

Gang of Four

Straight talk, it’s a translator.

Sample


Mediator

The intent for the mediator pattern is to define an object that encapsulates how a set of objects interacts. 
The mediator promotes lose coupling by keeping objects from referring to each other explicitly, and it lets you vary the interaction independently.

Gang of Four

It basically lets you control the communication between each object. As the name implies: mediator. It probably could have equally been called the dictator pattern.

Sample

Visitor

The visitor pattern’s intent is to represent an operation to be performed on the elements of an object structure. Also, visitors lets you define a new operation without changing the classes of the elements on which it operates.

Gang of Four

it basically lets you add and perform new functionality on objects without changing a structure that might ultimately lead to some problems.

Sample

Leave a Reply:

Your email address will not be published. Required fields are marked *