Design Pattern : Memento Pattern

Memento Design Pattern allows to capture internal state of an object in an external object and restore it to the desired checkpoint when required, all the while being in compliance with encapsulation. The Memento Design Pattern comprises of 3 actor classes. Originator : The class which needs to have the ability to store its internal … Continue reading Design Pattern : Memento Pattern

Design Patterns : Bridge Pattern

The essence of Bridge Pattern lies in the fact that it not just decouples the abstraction from implementation, but in doing so, allows both to evolve independently. Let's consider the examples of smartphones. The underlying OS (for sake of example, let's assume its Android) improving every year. The Android has seen atleast 7 versions in … Continue reading Design Patterns : Bridge Pattern

Design Patterns : Prototype Pattern

Falling under Creational Patterns, Prototype Pattern aims in creating a clone of your object and is used in scenarios when creating a object is considered costly (may be the creation involves a long Database or Web Service Operation). The formal definition of the pattern is as follows.   Specify the kind of objects to create … Continue reading Design Patterns : Prototype Pattern

Design Patterns : Decorator Pattern

While Inheritance/Sub Classing seems to be most natural way of extending functionality, it might not be always the best option. Especially when you want to avoid subclassing as it might result in too many classes. Consider the following scenario. Your nearest Dominos has many varieties of Pizzas. On top of it, you could decorate each … Continue reading Design Patterns : Decorator Pattern

Design Patterns : State Pattern

State Pattern is share a lot of similarities with Strategy Pattern, but has its own fundamental differences as well. The State pattern allows to change the behavior of a method, depending on the state of an object, in other words it encapsulates the behavior dependent on the state (the What). This is different from the … Continue reading Design Patterns : State Pattern

Design Patterns : Null Object Pattern

Null Pattern is probably one of the most underestimated and often most ignored among the design Patterns., though it turns out to be one of the easiest to implement. The intend of the pattern is to ensure we won't end up with NullReference Exceptions, while avoiding the long list of repeated preconditions that checks of … Continue reading Design Patterns : Null Object Pattern

Design Patterns : Adapter Pattern

There is already a large amount of literature on the Internet which discusses Adapter Pattern. However, the purpose of article is to showcase the implementations of the Adapter Pattern, rather than discussing the application of the pattern. In this post, adapter class is implemented using 1. Inheritance 2. Dependency Injection 3. Generics Consider your old … Continue reading Design Patterns : Adapter Pattern