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
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
A fully initialized instance to be copied or cloned
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.
Match interfaces of different classes
Separates an object’s interface from its implementation
A tree structure of simple and composite objects
Add responsibilities to objects dynamically
A single class that represents an entire subsystem
A fine-grained instance used for efficient sharing
- Private Class Data
Restricts accessor/mutator access
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
Encapsulate a command request as an object
A way to include language elements in a program
Sequentially access the elements of a collection
Defines simplified communication between classes
Capture and restore an object’s internal state
- Null Object
Designed to act as a default value of an object
A way of notifying change to a number of classes
Alter an object’s behavior when its state changes
Encapsulates an algorithm inside a class
- Template method
Defer the exact steps of an algorithm to a subclass
Defines a new operation to a class without change
Thank you very much, stay tuned for new articles. Peace✌🏼
Design Patterns and Refactoring
In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software…
Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you…
Design Pattern - Overview
Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns…
The 3 Types of Design Patterns All Developers Should Know (with code examples of each)
What is a Design Pattern?Design patterns are design level solutions for recurring problems that we software engineers…
Rozanski, N. (2014). Software systems architecture: Working with stakeholders using viewpoints and perspectives. Place of publication not identified: Addison-Wesley.