Design Patterns in OOP | Let’s Simplify

Hey Geeks! Are you planning to pursue a career in software development? If so, design patterns are a skill that you’ll need pickup soon. Therefore we introduce this new series, where we will dedicate one article to each pattern and attempt to explain it in the easiest way possible. But before we dive in, let us first look at what design patterns really are.

What are design patterns?

Building good software requires planning and design. Just like we design the user interface of an app, we also need to carefully design how we write the business logic. For example, consider the Logger class in Java. It helps us log events/messages to a file, in order for us to later use them for debugging. Now ask yourself this question:

Is it a good design decision to create a new object of the Logger class wherever we want to log messages in our code?

The answer is no. It may feel like, does it really matter? It doesn’t, if it’s a small application with five or six classes. But in real life, apps contain many classes and thousands of lines of code. Creating a new object every time we need to log something will overload the memory unnecessarily.

The solution then is to write the Logger class in such a way that, only one object of it can be created at a time. Instead of creating a new object, we just reuse the existing one. This saves lots of memory and hence makes our app perform better.

The Solution to Common Problems

Problems like the one stated above keep cropping up in software development. That’s why, experienced developers and engineers have come up with a list of patterns, or styles of coding, that alleviate these problems.

Therefore, design patterns in programming is nothing but a set of coding styles, that act as solutions to typical problems in software development. So how many design patterns are there? Design patterns are categorized into three segments:

  1. Creational Patterns
  2. Structural Patterns
  3. Behaviorial Patterns

Creational Patterns

Creational design patterns are concerned with the creation of objects. These solutions help one to create objects more effectively, depending on the situation. Here’s the list of patterns which come under this category:

  1. Singleton Pattern
  2. Builder Pattern
  3. Prototype Pattern
  4. Factory Pattern
  5. Abstract Factory Pattern

Structural Patterns

Structural design patterns are concerned with efficient assembly of different objects. Therefore, implementing these patterns wherever appropriate can make your application more scalable. The patterns under this category are:

  1. Adapter Pattern
  2. Bridge Pattern
  3. Composite Pattern
  4. Decorator Pattern
  5. Facade Pattern
  6. Flyweight Pattern
  7. Proxy Pattern

Behaviorial Patterns

Behaviorial design patterns contain solutions that help us to correctly assign responsibilities between objects. They are concerned more about algorithms. Following are the patterns included in this category:

  1. Chain of Responsibility Pattern
  2. Command Pattern
  3. Interpreter Pattern
  4. Iterator Pattern
  5. Mediator Pattern
  6. Memento Pattern
  7. Observer Pattern
  8. State Pattern
  9. Strategy Pattern
  10. Template Method Pattern
  11. Visitor Pattern

Going In-depth

So now you have the big picture. Design Patterns is a vast subject. Mastering it takes time, patience and practice. In order to do so, you will need resources that are easy to understand.

That’s why, we are going to take each design pattern from each category listed above and dedicate one article to each. We will explain them thoroughly with easy to understand examples. Each article will be directly linked from here.

Our language of choice for this free tutorial will be Java, for its excellent object-oriented programming implementation. See you in my next article, where we take a deep dive into the Singleton pattern! 😎

While I am writing the next tutorial, why not take a look at our pick of the top five websites to practice coding?

Recommended Reads