Prototype

1. Usage Pool of prototypical instances copying them-self to create new copy of objects. Reason can be expensive usage of new() command. Also such approach hide complexity. 2. UML class diagram 3. Pros Adding and removing products at run-time. Specifying new objects by varying values. Specifying new objects by varying structure. Reduced sub-classing. Configuring an […]

Builder

1. Usage To implement reusable mechanize of polymorphic pipeline to generate step by step final complex product. For example function “save as” document – as HTML, RTF, PDF. each plugin for different format will have its own way to serialize – table, image or title objects. 2. UML class diagram Source: https://sourcemaking.com/design_patterns/builder 3. Pros 4. […]

Abstract Factory

1. Usage When required to create family of related objects, and they should be easily changed to another family of related objects at run-time we use Abstract Factory; 2. UML class diagram 3. Pros – related objects grouped together; – easy switch at runtime between families of objects; – making uniform way of working with […]

Factory Method

1. Usage “Define an interface for creating an object, but let subclasses decide which class to instantiate. The Factory method lets a class defer instantiation it uses to subclasses.”(Gang Of Four) 2. UML class diagram 3. Pros – client can create objects without specifying subclass types. 4. Cons – hard to refactor existing code. – […]

Double Dispatch

Recently I was visiting one company and got C++ interview question: What is double dispatch. I studied C++ quite long time ago and that question confused me. Single Dispatch is calling virtual method based on V-Table (run-time) but double dispatch? After interview I always review subjects which made me hard time. Thats only reason for going to […]