Design Patterns

Ilyas Karimov
Nerd For Tech
Published in
4 min readDec 18, 2020

--

Hey, Folks! This article might be useful for future software engineers. We will talk about patterns and explain why they are used. If you don’t know about patterns, don’t worry. Without further ado…

In software engineering, a design pattern is a repeatable solution to the frequently happening issues in software design. A design pattern is not a complete pattern; it cannot be transformed into code directly. A pattern is a template that can be used to solve a problem in different situations. We have different patterns for implementing the undo feature, and one of them is the Memento pattern. Therefore, a design pattern shows you how a user should structure the classes and how the class should communicate with each other. Historically speaking, software engineers ignored to used existing patterns, but rather design their own solutions to problems. One of the reasons for this state of affairs used to be the lack of easily accessible, standard solutions for common software architecture and design problems. There are many different types of patterns available today.

There exist 23 design patterns that were originally documented in the 90s in the book called Design Patterns, Elements of Reusable Object-Oriented Software. The book was written by four authors, often referred to as Gang of Four. Therefore, those 23 design patterns are often referred to as the Gang of Four patterns. I personally recommend you to read the book.

There are 3 design pattern types, creational, structural, and behavioral. Creational patterns are all about different ways to create objects. Structural patterns are about the relationships between these objects. Behavioral patterns about negotiation and communication between these objects. Don’t forget that these design patterns do not represent all patterns and their work, there are unofficial and undocumented ones, but these are classic ones that every software engineer must understand.

Before introducing some of the patterns, let’s see why software engineers should study this topic. First, it helps to communicate with other developers at an abstract level, for example, telling your colleague that we need the command pattern to improve this code simply by mentioning its name. Second, it makes you a better designer, you learn how to build reusable extensible, and maintainable software. Last but not least, they help you learn and use new frameworks faster.

Before starting to learn the patterns, I kindly ask you to learn and revise your knowledge about OOP; classes, interfaces, encapsulation, abstraction, inheritance, polymorphism, UML.

Creational Design Patterns are all about class instantiations.

  • Abstract Factory
    Creates an instance of several families of classes
  • Builder
    Separates object construction from its representation
  • Factory Method
    Creates an instance of several derived classes
  • Object Pool
    Avoid expensive acquisition and release of resources by recycling objects that are no longer in use
  • Prototype
    A fully initialized instance to be copied or cloned
  • Singleton
    A class of which only a single instance can exist

Structural Design Patterns about how classes and objects can be composed, to form larger structures. The structural design patterns simplify the structure by identifying relationships.

  • Adapter
    Match interfaces of different classes
  • Bridge
    Separates an object’s interface from its implementation
  • Composite
    A tree structure of simple and composite objects
  • Decorator
    Add responsibilities to objects dynamically
  • Facade
    A single class that represents an entire subsystem
  • Flyweight
    A fine-grained instance used for efficient sharing
  • Private Class Data
    Restricts accessor/mutator access
  • Proxy
    An object representing another object

Behavioral Design Patterns are concerned with algorithms and the assignment of responsibilities between objects.

  • Chain of responsibility
    A way of passing a request between a chain of objects
  • Command
    Encapsulate a command request as an object
  • Interpreter
    A way to include language elements in a program
  • Iterator
    Sequentially access the elements of a collection
  • Mediator
    Defines simplified communication between classes
  • Memento
    Capture and restore an object’s internal state
  • Null Object
    Designed to act as a default value of an object
  • Observer
    A way of notifying change to a number of classes
  • State
    Alter an object’s behavior when its state changes
  • Strategy
    Encapsulates an algorithm inside a class
  • Template method
    Defer the exact steps of an algorithm to a subclass
  • Visitor
    Defines a new operation to a class without change

Thank you very much, stay tuned for new articles. Peace✌🏼

--

--

Ilyas Karimov
Nerd For Tech

Master of Computer Science and Data Analytics at ADA/GW Universities, Researcher, Psychology-lover, Meme-maker, Musician, Writer, AI & Sarcasms!