Home » Design Patterns

Tag Archives: Design Patterns

Builder Design Pattern

Hello Friends, In this tutorial, we will discuss Builder design pattern. Key topics we are going to discuss are : – Which category Builder Design Pattern falls in ? – What problem builder Pattern is solving or when to use Builder pattern? – Builder Pattern – Builder Pattern Example – Advantages of Builder Pattern – Disadvantages of Builder Pattern Which ...

Read More »

Composition over Permutations

I’m in the process of reworking an open-source library to make it operate more easily for my use cases. The writer of the library has a particular view of how software should be, and it will not co-exist with the sort of design patterns I’d like to use. I’d like to think that this is a question of too many ...

Read More »

Static Factories are Great!

Every now and then I jump on classes with multiple constructors or classes that are rigorous to work with. Let alone not being able to mock part of their components and at the end being forced to use reflection for testing (mockito based, old school, you choose). Imagine a Producer class that you use for Kafka. A class that provides ...

Read More »

What are Design Patterns?

Design patterns are solutions to known problems. The pattern represents an abstracted solution to a commonly experienced problem. As the solution is abstracted it is language agnostic. A non-programmatic analogy is to think about how to solve the problem of getting wet when it rains. A common problem in rainy countries like the UK. There are several solutions: wear a ...

Read More »

State Pattern

Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. Participants Context: defines the interface of interest to clients Maintains an instance of a ConcreteState subclass that defines the current state. State: defines an interface for encapsulating the behavior associated with a particular state of the Context. Concrete State: each ...

Read More »

Memento Pattern

Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later. Participants Memento: stores internal state of the Originator object. The memento may store as much or as little of the originator’s internal state as necessary at its originator’s discretion. Protect against access by objects of other than the originator. ...

Read More »

Strategy Design Pattern In Java

The strategy design pattern is a behavioral pattern in which we have multiple algorithms/strategies for achieving a task and which algorithm/strategy to use is left for the client to choose. The various algorithm options are encapsulated in individual classes. In this tutorial, we’ll learn to implement the strategy design pattern in Java. UML Representation: Let’s first start by looking at ...

Read More »

Mediator Design Pattern In Java

In this tutorial, we’ll learn about a behavioral pattern that promotes loose coupling between several objects communicating with one another. The idea behind the Mediator design pattern is to have a central object that encapsulates how a set of objects interact. In the mediator pattern, we extract all the relationships between different classes in a separate class known as a ...

Read More »

Chain Of Responsibility Design Pattern In Java

In this tutorial, we’ll learn how to implement the Chain Of Responsibility Pattern in Java. The Chain Of Responsibility design pattern involves having a chain of objects that are together responsible for handling a request. When a client sends a request, the first handler will try to process it. If it can process it, then the request processing ends here. ...

Read More »