Design Pattern - Structural Flashcards
Adapter
Works as a bridge between two incompatible interfaces. Involves a single class that is responsible to join functionalities of independent or incompatible interfaces.
Bridge
Used when we need to decouple an abstraction from its implementation so that the two can vary independently. Involves an interface that acts as a bridge making the functionality of concrete classes independent from interface implementer classes. Both types of classes can be altered structurally without affecting each other.
Composite
Used where we need to treat a group of objects in a similar way as a single object. Composes objects in terms of a tree structure to represent part as well as whole hierarchy. Creates a class that contains a group of its own objects. This class provides ways to modify its group of same objects.
Decorator
Allows a user to add new functionality to an existing object without altering its structure. Creates a decorator class that wraps the original class and provides additional functionality keeping class methods signature intact.
Facade
Hides the complexities of the system and provides an interface to the client using which the client can access the system. Involves a single class that provides simplified methods required by client and delegates calls to methods of existing system classes.
Flyweight
Primarily used to reduce the number of objects created and to decrease memory footprint and increase performance. Tries to reuse already existing similar kind objects by storing them and creates new object when no matching object is found.
Private Class Data
Prevents manipulation of data that is meant to be immutable by separating the data from the methods that use it into a class that maintains the data state. Used to encapsulate class attributes and their manipulation.
Proxy
A class represents functionality of another class. Creates a object having original object to interface its functionality to outer world.