Memento pattern

1. Usage Saves inner state of object in order to restore it in future. Usually implemented in Undo/Redo of Editors sometimes with Command Pattern. Memento in C++ implemented as Friend of Originator. Originator hide details of Memento providing narrow interface for controls. 2. UML class diagram Originator (managed a contained Memento obj), Memento(snapshot of originator […]

Chain of responsibility pattern

1. Usage Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. [GoF, p223] Launch-and-leave requests with a single processing pipeline that contains many possible handlers. An […]


1. Usage Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. [GoF, p175] Client-specified embellishment of a core object by recursively wrapping it. Wrapping a gift, putting it in a box, and wrapping the box. 2. UML class diagram 3. Pros Decorators provide a flexible alternative to […]


1. Usage Composite is composing tree like structures as single object(container), and let clients to go through such composed objects and regular objects uniformly. Qt Library has implicit support of Composite pattern due to ability to SetParent of QObject. 2. UML class diagram (source: Typical Composite Object structure: 3. Pros It makes it easy […]


1. Usage Kind of “2D Abstraction” (or by Rumbaugh “nested generalizations”) both on Interface(Window in example below) and on Implementation(WindowImp). So both Abstraction and Implementation should be extensible by sub-classing.Another name for this pattern is Handle-Body.This Pattern often used in Window Libraries e.g. AWT. Qt library uses this pattern for switching Style at run-time. Reasons […]


1. Usage Proxy pattern in general is Wrapper. Sometimes its hard/impossible to modify real object. For client using Proxy object should be same like using real object as they share same interface. Consider following usage scenarios: Remote Proxy – in distributed communication we create local proxy object which hide all communication with remote object Virtual […]