SOLID Design Principle Explained with Java

Introduction SOLID design principle is one of the most popular set of design principles in object-oriented software development. It’s a mnemonic acronym for the following five design principles: S – Single Responsiblity Principle O – Open Closed Principle L – Liskov Substitution Principle I – Interface Segregation Principle D – Dependency Inversion Principle

Continue

State Design Pattern in Java

Introduction State pattern comes under behavior design pattern in JEE. The State design pattern allows an object to alter its behavior when its internal state changes. State pattern is used to provide a systematic and lose-coupled way to achieve this through Context and State implementations. Context is the class that has a state reference to one of the concrete implementations of the state and forwards the request to the state object for processing. This can be a cleaner way for an object to change its behavior at runtime without resorting…

Continue

Strategy Design Pattern in Java

Introduction The strategy pattern is a behavioral design pattern that enables an algorithm’s behavior to be selected at runtime without causing tight coupling. The strategy pattern defines a family of algorithms, encapsulates each algorithm, and makes algorithms interchangeable. Strategy pattern lets the algorithm vary independently from clients that use it. So you define a strategy wherein a particular algorithm or implementation is applicable at runtime based on your requirement. The definition in original Gang of Four book is given below Define a family of algorithms, encapsulate each one, and make…

Continue

Observer Design Pattern in Java

Observer Pattern is one of the behavioral patterns. Observer design pattern is useful when there is something need to be done with the state of an object and an object wants to get notified whenever there is any change in state. In observer pattern, the object that watches on the state of another object are called Observer and the object that is being watched is called Subject. This pattern is useful when there is a one-to-many relationship between objects and when an object changes its state, all its dependent objects…

Continue

Memento Design Pattern in Java

Memento Pattern is one of the behavioral patterns. Memento pattern is a software design pattern that provides the ability to restore state of an object to its previous state. The memento pattern is implemented with three objects: the originator, a caretaker and a memento. The originator is an object that has an internal state. The caretaker asks the originator for a memento object. Then caretaker does something which make changes to the originator, but has the ability to undo the change. To roll back to the state before operations, it…

Continue

Mediator Design Pattern in Java

Mediator Pattern is one of the behavioral patterns as it deals with the behavior of the program. Usually a program is made up of a large number of classes. So the logic and computation are distributed among these classes. As more classes are developed in a program, the number of classes are increased, thus arising the problem of communication among these classes and it becomes much difficult to read and maintain. Therefore, the mediator pattern comes in rescue to the complexity which comes in the coding when number of classes…

Continue

Iterator Design Pattern in Java

Iterator pattern falls under behavioral design pattern. Iterator pattern is very commonly used design pattern in Java. This pattern is used to iterate through a collection of objects without exposing its underlying representation. It is used to access the elements of an aggregate object sequentially. For example, Java’s collections like ArrayList and HashMap have implemented the iterator pattern.

Continue

Command Design Pattern in Java

The command pattern comes under behavioral design pattern. The Command pattern is used to create objects that represent actions and events in an application. In the command pattern, a command interface declares a method for executing a particular action. A command object encapsulates an action or event and contains all information required to understand the action or event. This command object can be used as a parameter to extract information about occurred actions and events. In the command pattern, the invoker is decoupled from the action performed by the receiver.…

Continue

Chain of Responsibility Design Pattern in Java

The Chain of Responsibility is known as a behavioral pattern, as it is used to manage algorithms, relationships and responsibilities between objects. The Chain of Responsibility pattern consists of a series of processing objects where each object containing the type of commands it can handle. Each object in the series either does its own task or passes to the next object if it cannot handle the request. A mechanism also exists for adding new processing objects to the end of this chain or series. In this pattern objects in the…

Continue

Proxy Design Pattern in Java

The Proxy is known as a structural pattern, as it is used to form large object structures across many disparate objects. It functions as an interface to something else such as a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. For more information on usage or for below use cases you can refer to http://en.wikipedia.org/wiki/Proxy_pattern Use Cases Remote Proxy – Represents an object locally which belongs to a different address space. Take an example of ATM machine, it…

Continue