Home » Tag Archives: Design Patterns

Tag Archives: Design Patterns

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 »

Behavioural Design patterns: Observer

Observer is one of the most popular design patterns. It has been used a lot on many software use cases and thus many languages out there provide it as a part of their standard library. By using the observer pattern we can tackle the following challenges. Dependency with objects defined in a way that avoids tight coupling Changes on an ...

Read More »

Behavioural Design patterns: Memento

The memento pattern is all about state. You use it when you want to restore the object to its previous state. You have an object, you apply some actions and you are able to revert those actions and get the object in the various states it has been before. Most of us implement various algorithms and sometimes we do need ...

Read More »

Behavioural Design Patterns: Mediator

Previously we had a look at the iterator pattern. The mediator pattern is way different on what it tries to achieve. It is one of the behavioural patterns and its purpose is to alter the way objects communicate with each other. Instead of the objects communicating with each other directly the mediator will handle the objects interaction. For example imagine ...

Read More »

Multilevel Adapter Pattern

Intro This post continues my “new pattern ideas” series. I’ll describe a special version of the adapter pattern that can guarantee several levels of access to objects. In particular I’ll show 3 main levels – read, write and class access. Motivation We’ll consider a 2-tiered system: The top tier consists of object folders. Every folder contains objects of one type ...

Read More »