Design patterns

We understand the design patterns as method of producing well-design, structured, clean and reusable code. In this section we present examples of all design patterns used in this library. The aim of this presentation is to define the common dictionary of design patterns that will help to understand and use this library by people that did not take part in development process. While developing this library, authors were mostly inspired by Joshi's book [28] and classic Gang of Four [23] . We consider the Head First handbook [13] as best introduction to design pattern (despite the fact that the examples are written in Java). Also Duffy's books ([7] and [8] ) contain short introduction to design patterns used in financial engineering.

1. Virtual Copy Constructor, CRTP and Deep Copy

Virtual Copy Constructor is used to create a copy of an object without knowing its concrete type. It is needed when we want to use deep-copying smart pointer. Virtual copy constructor is usually implemented as clone method to which creation of object's copy is delegated. To avoid having to implement clone method in each derived class, one can use the Curiously Recurring Template Pattern idiom.

Virtual Copy Constructor, CRTP and Deep Copy

2. Factory

GoF description:Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory lets a class defer instantiation to subclasses.

Factory

3. Builder

GoF description: Separate the construction of a complex object from its representation so that the same construction process can create different representations.

Builder

4. Decorator

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

Decorator

5. Strategy

GoF description: Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Strategy

6. Visitor

Visitor is used to emulate double dispatch. Double dispatch is a special form of multiple dispatch, and a mechanism that dispatches a function call to different concrete functions depending on the runtime types of two objects involved in the call.

Visitor

7. Bridge

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

Bridge