As wikipedia says:-

In software engineering, a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into source or machine code. Rather, it is a description or template for how to solve a problem that can be used in many different situations. Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system.

Design patterns are general guidelines to solve a problem in software engineering. You can make better use of design patterns in object oriented programming language.

Uses of Design Patterns

Design patterns provide common platform for developers for specific problems for example singleton is the most common and not to mention one of the easiest to understand and implement, is used to share a single instance of a class through out the application or a request or any other scenario. So you know when to use it and how to use it. Hence it keeps all developers on a single page when such scenario comes.

Design patterns have evolved overtime and been through many minds so you know that these are the best practices for given scenarios.

Types of Design Patterns

Design patterns are categorized in 3 types or sub-classes which are following:

  • Creational Patterns
  • Structural Patterns
  • Behavioral Patterns

Lets dive into each type and the patterns comes under them.

Creational Design Patterns

Creational patterns deals with creational mechanisms of objects which increase scalability and reusability of code.

Factory – Creates an instance of several derived classes without exposing creation logic.
Abtract Factory – Creates an instance of several families of without specifying their concrete classes.
Builder – Separates complex object construction from its representation
Prototype – A fully initialized instance to be copied or cloned
– Ensure a class has only one instance, and provide a global point of access to it.

Structural Design Patterns

Structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships among entities.

Adapter – Allows objects with incompatible interfaces to collaborate. Works as a translator.
Bridge – Splits large class into two separate hierarchies. Which can be developed independently of each other.
Composite – A tree structure of simple and composite objects.
Decorator – Attach new behavior to an object inside wrapper objects dynamically.
Facade – Provides a simplified interface of a single class that represents an entire subsystem.
Flyweight – A fine-grained instance used for efficient sharing.
Proxy – An object representing another object.

Behavioral Design Patterns

Behavioral design patterns are design patterns that deal with algorithms and assignments 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.
Observer – A way of notifying change to a number of subscriber 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.

As I move forward to each of the design pattern I will be writing about it and posting source code over github. See you soon!

Thanks for stopping by! Happy coding!