Author: saqibkhan

  • MVC Pattern

    MVC Pattern stands for Model-View-Controller Pattern. This pattern is used to separate application’s concerns. Implementation We are going to create a Student object acting as a model.StudentView will be a view class which can print student details on console and StudentController is the controller class responsible to store data in Student object and update view StudentView accordingly. MVCPatternDemo, our demo class, will use StudentController to demonstrate…

  • Visitor Pattern

    In Visitor pattern, we use a visitor class which changes the executing algorithm of an element class. By this way, execution algorithm of element can vary as and when visitor varies. This pattern comes under behavior pattern category. As per the pattern, element object has to accept the visitor object so that visitor object handles…

  • Template Pattern

    In Template pattern, an abstract class exposes defined way(s)/template(s) to execute its methods. Its subclasses can override the method implementation as per need but the invocation is to be in the same way as defined by an abstract class. This pattern comes under behavior pattern category. Implementation We are going to create a Game abstract class defining…

  • Strategy Pattern

    In Strategy pattern, a class behavior or its algorithm can be changed at run time. This type of design pattern comes under behavior pattern. In Strategy pattern, we create objects which represent various strategies and a context object whose behavior varies as per its strategy object. The strategy object changes the executing algorithm of the…

  • Null Object Pattern

    In Null Object pattern, a null object replaces check of NULL object instance. Instead of putting if check for a null value, Null Object reflects a do nothing relationship. Such Null object can also be used to provide default behaviour in case data is not available. In Null Object pattern, we create an abstract class…

  • State Pattern

    In State pattern a class behavior changes based on its state. This type of design pattern comes under behavior pattern. In State pattern, we create objects which represent various states and a context object whose behavior varies as its state object changes. Implementation We are going to create a State interface defining an action and concrete state…

  • Observer Pattern

    Observer pattern is used when there is one-to-many relationship between objects such as if one object is modified, its depenedent objects are to be notified automatically. Observer pattern falls under behavioral pattern category. Implementation Observer pattern uses three actor classes. Subject, Observer and Client. Subject is an object having methods to attach and detach observers…

  • Memento Pattern

    Memento pattern is used to restore state of an object to a previous state. Memento pattern falls under behavioral pattern category. Implementation Memento pattern uses three actor classes. Memento contains state of an object to be restored. Originator creates and stores states in Memento objects and Caretaker object is responsible to restore object state from…

  • Mediator Pattern

    Mediator pattern is used to reduce communication complexity between multiple objects or classes. This pattern provides a mediator class which normally handles all the communications between different classes and supports easy maintenance of the code by loose coupling. Mediator pattern falls under behavioral pattern category. Implementation We are demonstrating mediator pattern by example of a…

  • Iterator Pattern

    Iterator pattern is very commonly used design pattern in Java and .Net programming environment. This pattern is used to get a way to access the elements of a collection object in sequential manner without any need to know its underlying representation. Iterator pattern falls under behavioral pattern category. Implementation We’re going to create a Iterator interface which…