Home » Design Patterns » Page 2

Tag Archives: Design Patterns

Facade Design Pattern In Java

Facade means the face of a building. While passing across a street, all we look at is the face of a building. The face abstracts all the complex implementation details of a building. Similarly, a facade design pattern aims to provide a unified interface to a set of interfaces in the subsystem. This unified interface hides the subsystem complexity from ...

Read More »

Composite Design Pattern In Java

A composite design pattern is useful when we have to work with a tree-like hierarchical structure of objects. It lets us treat the individual objects and the composition of objects uniformly. It falls under the category of a structural design pattern as it composes objects into a tree structure to represent part-whole hierarchies. UML Representation: The UML representation of a ...

Read More »

Adapter Design Pattern In Java

The Adapter design pattern is a structural design pattern that helps us to connect to the legacy or third-party code that exposes a similar functionality through a different interface. A real-world analogy for an adapter is the one we use to connect our USB cable to an ethernet port. While designing an object-oriented application, we might feel the need for an adapter when say our ...

Read More »

New life of old Visitor design pattern

Introduction Visitor [1, 2] is a widely known classical design pattern. There are a lot of resources that explain it in details. Without digging into the implementation I will briefly remind the idea of the pattern, will explain its benefits and downsides and will suggest some improvements that can be easily applied to it using Java programming language.  Classical Visitor [Visitor] ...

Read More »

Behavioural Design Patterns: Visitor

Our last pattern of the behavioural design patterns is going to be the visitor pattern. We use the visitor pattern when we want to make it possible to define a new operation for classes of an object structure without changing the classes. Imagine the scenario of a software that executes http requests to an api. Most http apis out there ...

Read More »

Behavioural Design Patterns: Template method

Previously we used the strategy pattern to in order to solve the problem of choosing various speeding algorithms based on the road type. The next behavioural design pattern we are going to use is the template method.By using the template method we define the skeleton of the algorithm and the implementation of certain steps is done by subclasses. Thus we ...

Read More »

Behavioural Design Patterns: Strategy

Previously we used the state in order to add some functionality to an application based on the user state. Our next behavioural design pattern is Strategy. The strategy pattern enables us to select an algorithm at runtime. Based on the instructions our program will pick the most suitable algorithm instead of implementing an algorithm directly. This makes our codebase more ...

Read More »

Test-Driven Development – you are doing it wrong!

Test-Driven Development is one of those techniques that somehow is not as widely used as it should be. I know a lot of developers who can agree on the benefits it brings. Yet the same developers, when asked about practicing TDD, answer: “it does not work for me”.When I tried to understand the “why” behind this statement, they start to ...

Read More »

Behavioural Design patterns: State

The state pattern deals with altering an object’s behaviour when its state changes. Imagine the case of a class responsible for generating user interface based on the state. You got anonymous, logged-in and admin users. We shall create an interface called GreetingState which defines the action of drawing a html text with a welcome message to the user. There is ...

Read More »