Design Patterns — Part 1: Introduction

Cesar Kohl
2 min readJul 29, 2019

--

We can define Design Patterns as solution templates for some specific problem often encountered within a software project. They serve as templates to apply to develop a solution to problems.

It is not implemented code that can be copied to other software (most of the time), but just the definition of your application. Therefore, they work in various types of scopes and for various purposes. You can apply a specific Design Pattern to both a game and a sales site, it all depends on your need.

Another consideration is that Design Patterns are independent of the language used. They work in most object-oriented languages, however, they may contain some differences in their implementations — which will depend on the functionality available and the peculiarities of each of these languages.

When applied correctly and for a real need, Design Patterns are considered great development practices.

The Origin of Design Patterns

It all began in 1987, when Kent Beck and Ward Cunningham tackled the first Software Design Patterns at a US conference developed at Smalltalk (popular language at the time). However, patterns began to take shape only in 1995 from the publication of the book Design Patterns: Elements of Reusable Object-Oriented Software, written by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, who became known as “ Gang of Four “(or GOF).

There are many documented Design Patterns on the web, but undoubtedly, those developed by GOF are the best known. In total there are 23 patterns divided into three categories:

  • Creational standards;
  • Structural patterns;
  • Behavioral patterns.

Creational Patterns

Responsible for abstracting object creation, they transfer and centralize responsibilities for how and where to instantiate them, making the system more flexible. GOF’s creation defaults are:

  • Abstract Factory
  • Builder
  • Factory Method
  • Prototype
  • Singleton

Structural patterns

Structural patterns define how classes and objects are composed with each other, allowing changes to this composition at runtime. They are more related to structure as classes and objects are linked.

The structural standards set by the GOF are:

  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy

Behavioral patterns

They define the communication between classes and objects, as well as their behaviors. They are directly linked to the attribution of responsibilities of these objects and how the algorithms behave.

The behavioral standards set by the GOF are:

  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Observer
  • State
  • Strategy
  • Template Method
  • Visitor

Conclusion

There are several types of patterns are most PHP frameworks use one of them to create order and logic within the code. In the next articles we'll dive deep into how to apply them with PHP.

--

--