Design Patterns Part 3

June 2, 2020

Part 1, 2, 3


Proto Type

It’s intent of the prototype pattern to specify the kinds of objects to create using a prototypical instance and create new objects by copying this prototype.

Gang of Four

the goal of the prototype pattern is to create an object based on another object.

Sample

Bridge

the indent for the bridge pattern is to decouple an abstraction from its implementation so that the two can vary independently.

Gang of Four

That it’s used to separate an abstraction from its implementation so both are modified independently.

Sample

Façade

The façade pattern’s intent is to provide a unified interface to a set of interfaces in a subsystem. The façade defines a higher-level interface that makes the subsystem easier to use.

Gang of Four

It’s used to hide complexities of a system and provides an interface to the client to do so.

Sample

Flyweight

Defined the intent of the Flyweight Pattern as being able to use sharing to support large numbers of fine-grained objects efficiently.

Gang of Four

As being able to eliminate the need of creating new objects that already exist by sharing existing ones.

Sample

Proxy

The intent for the proxy pattern is to provide a surrogate or placeholder for another object to control access to it.

Gang of Four

It provides objects that references other objects for their functionality.

Sample

Memento

Without violating encapsulation, capture and externalize an object internal state so that the object can be restore to this state later.

Gang of Four

This pattern is used to track states of an object to go back and forth between. Just like when you’re undoing and redoing.

Sample

After undo:

State

The intent of a State Pattern is to alter its behavior when it’s internal state changes. And as a result the object will appear to change its class.

Gang of Four

It allows an object to change what it does based on its current state.

Sample

This pattern is most useful when you want an object to change its behavior based on its internal state. And for our scenario we can prevent a user from withdrawing money when it’s in an overdrawn state. But more permissions to access features could have been added or removed based on the account’s state. So in the end, anytime you want an object behavior to change automatically based on its internal state think of, as the name applies, the state pattern.

Strategy

The strategy pattern’s intent is to define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Gang of Four

It allows a client to change an algorithm from a group of algorithms, and gives it a simple way to access it.

Sample

Template Method

Is to define the skeleton of an algorithm in an operation deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.

Gang of Four

It allows child classes to change some steps of an algorithm without changing the algorithm’s structure.

Sample

Leave a Reply:

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