Design Patterns | Eklavya Online

Design Patterns

Factory Method Pattern

Factory Pattern or Factory Method Pattern says that just define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate. In other words, subclasses are responsible to create the instance of the class. The Factory Method Pattern is also known as Virtual Constructor. Advantage of Factory Design Pattern Factory Method …

Factory Method Pattern Read More »

Iterator Pattern

Iterator Pattern According to GoF, Iterator Pattern is used “to access the elements of an aggregate object sequentially without exposing its underlying implementation”. The Iterator pattern is also known as Cursor. In collection framework, we are now using Iterator that is preferred over Enumeration. Advantage of Iterator Pattern It supports variations in the traversal of a collection. …

Iterator Pattern Read More »

Abstract Factory Pattern

Abstract Factory Pattern Abstract Factory Pattern says that just define an interface or abstract class for creating families of related (or dependent) objects but without specifying their concrete sub-classes.That means Abstract Factory lets a class returns a factory of classes. So, this is the reason that Abstract Factory Pattern is one level higher than the Factory …

Abstract Factory Pattern Read More »

Mediator Pattern

Mediator Pattern A Mediator Pattern says that “to define an object that encapsulates how a set of objects interact”. I will explain the Mediator pattern by considering a problem. When we begin with development, we have a few classes and these classes interact with each other producing results. Now, consider slowly, the logic becomes more …

Mediator Pattern Read More »

Singleton design pattern

Singleton Pattern says that just“define a class that has only one instance and provides a global point of access to it”. In other words, a class must ensure that only single instance should be created and single object can be used by all other classes. There are two forms of singleton design pattern Early Instantiation: creation …

Singleton design pattern Read More »

Memento Pattern

Memento Pattern A Memento Pattern says that “to restore the state of an object to its previous state”. But it must do this without violating Encapsulation. Such case is useful in case of error or failure. The Memento pattern is also known as Token. Undo or backspace or ctrl+z is one of the most used operation …

Memento Pattern Read More »

Prototype Design Pattern

Prototype Pattern says that cloning of an existing object instead of creating new one and can also be customized as per the requirement. This pattern should be followed, if the cost of creating a new object is expensive and resource intensive. Advantage of Prototype Pattern The main advantages of prototype pattern are as follows: It reduces …

Prototype Design Pattern Read More »

Observer Pattern

Observer Pattern An Observer Pattern says that “just define a one-to-one dependency so that when one object changes state, all its dependents are notified and updated automatically”. The Memento pattern is also known as Dependents or Publish-Subscribe. Benefits: It describes the coupling between the objects and the observer. It provides the support for broadcast-type communication. …

Observer Pattern Read More »

Builder Design Pattern

Builder Pattern says that “construct a complex object from simple objects using step-by-step approach” It is mostly used when object can’t be created in single step like in the de-serialization of a complex object. Advantage of Builder Design Pattern The main advantages of Builder Pattern are as follows: It provides clear separation between the construction and …

Builder Design Pattern Read More »

State Pattern

State Pattern A State Pattern says that “the class behavior changes based on its state”. In State Pattern, we create objects which represent various states and a context object whose behavior varies as its state object changes. The State Pattern is also known as Objects for States. Benefits: It keeps the state-specific behavior. It makes …

State Pattern Read More »