Design Patterns

C++ Builder Pattern

Builder Pattern Builder pattern in useful when you want to build a complex object. Intent of this pattern is to separate the construction of object from its representation. Abstract the construction of object and then derived concrete implementations will give respective construction parts. The director makes sure that the product (complex object) is properly created …

C++ Builder Pattern Read More »

C++ Composite Pattern

Composite Pattern Composite pattern is useful when you want to treat a group of objects in the same manner as a single instance of the object. The objects grouped, themselves could be in composite manner in a tree fashion. The primitive and compound objects are treated uniformly. A component interface is defined and both the …

C++ Composite Pattern Read More »

C++ Decorator Pattern

Decorator Pattern Useful, when you want to add capabilities (statically or dynamically) to an object without sub-classing the concrete object’s class as well as not affecting other objects of the same concrete class. Sample Program #include <iostream>#include <string>using namespace std;class actor {public:actor() {}virtual void act() {}virtual string name() {}};class actorConcretePerson: public actor {public:actorConcretePerson(string name) { …

C++ Decorator Pattern Read More »

Visitor Pattern

What is a visitor pattern? The visitor pattern is a behavioral design pattern.  Visitor pattern allows to separate the data structures and the algorithms to be applied on the data. Both data structure objects and algorithm objects can evolve separately. Makes development and changes easier. Data structure (element) objects have an “accept” method which take in a visitor (algorithmic) …

Visitor Pattern Read More »

Facade Pattern

What is Facade Pattern? Facade pattern is a structural design pattern. Makes an existing complex software library easier to use by providing a simpler interface for common tasks. Allows the applications/ clients using the library de-coupled from inner workings of a complex library. Demonstrate a simple Facade Pattern in C++ #include <iostream>using namespace std;// Transfer …

Facade Pattern Read More »

Adapter Pattern

What is Adapter pattern ? Adapter pattern is a structural design pattern. Also referred as wrapper pattern. An adapter allows classes to work together that normally could not because of incompatible interfaces, by providing its interface to clients while using the original interface. The adapter translates calls to its interface into calls to the original …

Adapter Pattern Read More »

Command Pattern

What is Command Pattern? Command pattern is a behavioral design pattern. Encapsulates a command/ request. The command itself is treated as an object. Classes participating in a command pattern include:- Command:- An abstract interface defining the execute method. Concrete Commands:- Extend the Command interface and implements the execute method. Invokes the command on the receiver object. …

Command Pattern Read More »

C++ Template Pattern

What is template design pattern? Template pattern is a behavioral design pattern. This has nothing to do with C++ templates as such. Template patterns is a common form in object oriented programming. Having an abstract base class (one or more pure virtual functions) is a simple example of template design pattern. In the template pattern, …

C++ Template Pattern Read More »

About Design Patterns

What is a Design Pattern? Design patterns describe recurring software design problems and their solutions. Design patterns assign in reuse of software architectures. Design patterns are independent of any programming language and they don’t talk about code re-use. The book “Design Patterns: Elements of Reusable Object-Oriented Software” also referred as “GoF (Gang of Four) Book” …

About Design Patterns Read More »

Chain of Responsibility

What is Chain of Responsibility Pattern? Chain of Responsibility is a behavioral design pattern. The basic idea behind this pattern is that a request or a command passes through a chain of objects until it is handled. Objects involved in this pattern are of two types. Processing Objects and Command Objects. Processing objects handle the commands …

Chain of Responsibility Read More »