First let’s start with why design patterns exist! Developers have noticed that they seemed to be approaching problems in similar ways in a bunch of different software’s, then they decided that it would be pretty useful to be able to talk about those approaches using a common vocabulary, so they wouldn’t have to keep explaining what they were referring to. Thus they figured out general versions of these common practices and gave them names like “Adapter” and “Singleton.”
A design pattern is only a description or template for how to solve a problem! that can be used in many different situations. So every design pattern provide a solution to commonly occurring software design problems. Patterns are formalized best practices that the Software Developer can use to solve common problems when designing an application.
In the case of object-oriented programming paradigm, design patterns are generally aimed at solving the problems of object generation and communication, rather than the larger scale problems of overall software architecture. Note: Patterns that imply object-orientation or more generally mutable state, are not as applicable in functional programming languages.
At a higher level then the design patterns there are architectural patterns that are larger in scope, usually describing an overall pattern followed by an entire system.
Below is thew difference between, Programming Paradigms, Architectural Patterns, Design Patterns and Design Principles:
- Programming Paradigms: A way to classify programming languages based on their coding styles and features. Some paradigms are concerned mainly with implications for the execution model of the language (Procedural, Functional, Object-oriented…).
- Architectural Patterns: Reusable solution to a commonly occurring problem in software architecture within a given context. They are similar to software design pattern but have a broader scope (MVC, Micro-services, Layered...).
- Design Patterns: Reusable solution to a commonly occurring problem in software design within a given context. It is a description or template for how to solve a problem that can be used in many different situations (Bridge, Builder, Strategy…).
- Design Principles: Represent a set of guidelines that help developers to avoid having a bad design. Writing code according to proven principles helps achieving code maintainability and simplicity(KISS, Liskov Substitution, Inversion of Control…).
There is 3 major types of design patterns:
Creational patterns provide ways to instantiate single or groups of objects. Making it easier to create objects in a way that suits the situation.
Some Creational Patterns:
- Factory Method. The factory pattern is used to replace class constructors, abstracting the process of object generation so that the type of the object instantiated can be determined at run-time.
- Singleton. The singleton pattern ensures that only one object of a particular class is ever created. All further references to objects of the singleton class refer to the same underlying instance.
- Abstract Factory. The abstract factory pattern is used to provide a client with a set of related or dependent objects. The “family” of objects created by the factory are determined at run-time.
Structural patterns provide a manner to define relationships between classes or objects. Making it easier for these entities to work together.
Some Structural Patterns:
- Facade. The facade pattern is used to define a simplified interface to a more complex subsystem.
- Adapter. The adapter pattern is used to provide a link between two otherwise incompatible types by wrapping the “adaptee” with a class that supports the interface required by the client.
- Decorator. The decorator pattern is used to extend or alter the functionality of objects at run-time by wrapping them in an object of a decorator class. This provides a flexible alternative to using inheritance to modify behavior.
Behavioral patterns define manners of communication between classes and objects. Making it easier and more flexible for these entities to communicate.
Some Behavioral Patterns:
- Observer. The observer pattern is used to allow an object to publish changes to its state. Other objects subscribe to be immediately notified of any changes.
- Mediator. The mediator pattern is used to reduce coupling between classes that communicate with each other. Instead of classes communicating directly, and thus requiring knowledge of their implementation, the classes send messages via a mediator object.
- Chain of Responsibility. The chain of responsibility pattern is used to process varied requests, each of which may be dealt with by a different handler.
Follow me on Twitter Mahmoud Zalt