Software Development

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 hat, stay at home and wait for the rain to stop, run fast so as to avoid most of the rain. These are not the best solutions, they go some way to reduce getting wet or avoiding the wetness altogether. But none are really that satisfactory.

What we need is a way to leave the house, not get wet and to do so with minimal effort and cost. We want some kind of cover over our head that deflects the rain. This is the abstraction of the solution.

Luckily we have solved this problem with the invention of the umbrella.

The umbrella design pattern

It prevents 99% of the rain while allowing us to leave the house. The umbrella is the implementation of the abstraction and it can be implemented in many ways, colours, shapes, and sizes. We choose the way that it is implemented and it does not matter as long as it follows the ‘pattern’ of an umbrella it will always keep your head dry.

Implementations of the Umbrella design pattern

This is, in essence, the idea of a design pattern. A reusable abstraction of a solution to a common problem.

How did Design Patterns arise?

Design pattern has been around for many years and the concept of reusable solutions has been around for millenniums and have been used extensively in architecture. However, the most important influence in the design pattern was the publication of the book Design Patterns: Elements of Reusable Object-Oriented Software in 1994. The authors have become very well known and respected in the Java community and are known as the gang of four.

The definition given to design patterns by the gang of four is that design patterns are:

“descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.”

Seminal work on design patterns

Design Patterns: Elements of Reusable Object-Oriented Software is the seminal work on design patterns and is still in publication today. The fact that it is still relevant stands as testimony to the reusability of design patterns. However, this book was written before the existence of Enterprise Java and therefore does not show how to implement the design patterns in Java EE. This is why myself (Alex Theedom) and Murat Yener collaborated on a book that explains how to implement many of the Gang of Four design patterns in Java EE. We show how to implement patterns like Singleton Pattern, Factory pattern, Façade Pattern, Decorator Pattern and Observer Pattern.

Published on Java Code Geeks with permission by Alex Theedom, partner at our JCG program. See the original article here: What are Design Patterns?

Opinions expressed by Java Code Geeks contributors are their own.

Alex Theedom

Alex Theedom is a Senior Java Developer and has recently played a pivotal role in the architectural design and development of a microservice based, custom built lottery and instant win game platform. Alex has experience of Java web application development in a diverse range of fields including finance, e-learning, lottery and software development. He is the co-author of Professional Java EE Design Patterns and many articles.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button