Skip to main content
Facade

Intent

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

Explanation

Real-world example

How does a goldmine work? "Well, the miners go down there and dig gold!" you say. That is what you believe because you are using a simple interface that goldmine provides on the outside, internally it has to do a lot of stuff to make it happen. This simple interface to the complex subsystem is a facade.


iluwatarAbout 3 minStructuralCode simplificationEncapsulationGang Of FourObject composition
Mediator

Intent

Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling
by keeping objects from referring to each other explicitly, and it lets you vary their interaction
independently.

Explanation

Real-world example

Rogue, wizard, hobbit, and hunter have decided to join their forces and travel in the same
party. To avoid coupling each member with each other, they use the party interface to
communicate with each other.


iluwatarAbout 3 minBehavioralGang Of FourDecoupling
Observer

Also known as

Dependents, Publish-Subscribe

Intent

Define a one-to-many dependency between objects so that when one object changes state, all its
dependents are notified and updated automatically.

Explanation

Real-world example

In a land far away live the races of hobbits and orcs. Both of them are mostly outdoors so they
closely follow the weather changes. One could say that they are constantly observing the
weather.


iluwatarAbout 2 minBehavioralGang Of FourReactive
Prototype

Intent

Specify the kinds of objects to create using a prototypical instance, and create new objects by
copying this prototype.

Explanation

First, it should be noted that the Prototype pattern is not used to gain performance benefits. It's only
used for creating new objects from prototype instances.


iluwatarAbout 2 minCreationalGang Of FourInstantiation
Proxy

Also known as

Surrogate

Intent

Provide a surrogate or placeholder for another object to control access to it.

Explanation

Real-world example

Imagine a tower where the local wizards go to study their spells. The ivory tower can only be
accessed through a proxy which ensures that only the first three wizards can enter. Here the proxy
represents the functionality of the tower and adds access control to it.


iluwatarAbout 2 minStructuralGang Of FourDecoupling