Abstract Document

Intent

Use dynamic properties and achieve flexibility of untyped languages while keeping type-safety.

Explanation

The Abstract Document pattern enables handling additional, non-static properties. This pattern uses concept of traits to enable type safety and separate properties of different classes into set of interfaces.


iluwatarStructuralExtensibilityAbout 2 min
Adapter

Also known as

Wrapper

Intent

Convert the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Explanation

Real-world example

Consider that you have some pictures on your memory card and you need to transfer them to your computer. To transfer them, you need some kind of adapter that is compatible with your computer ports so that you can attach a memory card to your computer. In this case card reader is an adapter. Another example would be the famous power adapter; a three-legged plug can't be connected to a two-pronged outlet, it needs to use a power adapter that makes it compatible with the two-pronged outlets. Yet another example would be a translator translating words spoken by one person to another


iluwatarStructuralGang of FourAbout 3 min
Ambassador

Intent

Provide a helper service instance on a client and offload common functionality away from a shared resource.

Explanation

Real world example

A remote service has many clients accessing a function it provides. The service is a legacy application and is impossible to update. Large numbers of requests from users are causing connectivity issues. New rules for request frequency should be implemented along with latency checks and client-side logging.


iluwatarStructuralDecouplingCloud distributedAbout 2 min
Bridge

Also known as

Handle/Body

Intent

Decouple an abstraction from its implementation so that the two can vary independently.

Explanation

Real-world example

Consider you have a weapon with different enchantments, and you are supposed to allow mixing different weapons with different enchantments. What would you do? Create multiple copies of each of the weapons for each of the enchantments or would you just create separate enchantment and set it for the weapon as needed? Bridge pattern allows you to do the second.


iluwatarStructuralGang of FourAbout 2 min
Business Delegate

Intent

The Business Delegate pattern adds an abstraction layer between presentation and business tiers. By using the pattern we gain loose coupling between the tiers and encapsulate knowledge about how to locate, connect to, and interact with the business objects that make up the application.


iluwatarStructuralDecouplingAbout 2 min
Composite

Intent

Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

Explanation

Real-world example

Every sentence is composed of words which are in turn composed of characters. Each of these objects are printable and they can have something printed before or after them like sentence always ends with full stop and word always has space before it.


iluwatarStructuralGang of FourAbout 2 min
Composite Entity

Intent

It is used to model, represent, and manage a set of persistent objects that are interrelated, rather than representing them as individual fine-grained entities.

Explanation

Real world example

For a console, there may be many interfaces that need to be managed and controlled. Using the composite entity pattern, dependent objects such as messages and signals can be combined together and controlled using a single object.


iluwatarStructuralEnterprise Integration PatternAbout 1 min
Composite View

Name

Composite View

Intent

The purpose of the Composite View Pattern is to increase re-usability and flexibility when creating views for websites/webapps. This pattern seeks to decouple the content of the page from its layout, allowing changes to be made to either the content or layout of the page without impacting the other. This pattern also allows content to be easily reused across different views easily.


iluwatarStructuralEnterprise Integration PatternPresentationAbout 5 min
Decorator

Also known as

Wrapper

Intent

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

Explanation

Real-world example

There is an angry troll living in the nearby hills. Usually, it goes bare-handed but sometimes it has a weapon. To arm the troll it's not necessary to create a new troll but to decorate it dynamically with a suitable weapon.


iluwatarStructuralGang of FourExtensibilityAbout 3 min
Delegation

Also known as

Proxy Pattern

Intent

It is a technique where an object expresses certain behavior to the outside but in reality delegates responsibility for implementing that behaviour to an associated object.

Explanation

Real-world example

Imagine that we have adventurers who fight monsters with different weapons depending on their abilities and skills. We must be able to equip them with different ones without having to modify their source code for each one. The delegation pattern makes it possible by delegating the dynamic work to a specific object implementing an interface with relevant methods.


iluwatarStructuralDecouplingAbout 1 min
2
3