Design Patterns Summary

Design pattern is useful as an abstraction tool for solving design problems in every discipline of engineering and architecture. A design pattern is a template for an object or class design that solves a recurring problem. Design patterns are helpful to document the creational, structural, and behavioral characteristics of the software. Separating the user interface from the logic, for example, offers these three distinct advantages:

? Interfaces are better defined and more specific to a device

? Apps become more adaptable to changing requirements

? Objects are reusable

Types of Design Patterns

In Software Engineering there are mainly 3 categories of Design Patterns.

?      Creational Patterns

?      Structural Patterns

?    Behavioural Patterns


Creational Design Patterns

?      The creational patterns aim to separate a system from how its objects are created, composed, and represented. 

?      They increase the system's flexibility in terms of the what, who, how, and when of object creation

?      Creational design patterns are composed of two dominant ideas. One is encapsulating knowledge about which concrete classes the system uses. Another is hiding how instances of these concrete classes are created and combined.

?      There are mainly 5 Creational Patterns as below

o  Singleton 

o  Abstract Factory

o  Builder

o  Factory Method

o  Prototype

Factory Methods (Creational Pattern)

?      Define an interface for creating an object, but let subclasses decide which class to instantiate. 

?      Factory Method lets a class defer instantiation to subclasses. 


Abstract Factory (Creational  Pattern)

?      Provides a way to encapsulate a group of individual factories that have a common theme. 

?      In normal usage, the client software creates a concrete implementation of the abstract factory and then uses the generic interfaces to create the concrete objects that are part of the theme. 

?      Client does not know (or care) which concrete objects it gets from each of these internal factories since it uses only the generic interfaces of their products. It separates details of implementation of a set of objects from their general usage.


Builder Pattern (Creational Pattern)

?      Separate construction of a complex object from its representation so that the same construction process can create different representations. 

?      Parse a complex representation, create one of several targets. 

?      Difference Between Builder and Abstract Factory 

–     Builder focuses on constructing a complex object step by step. Abstract Factory emphasizes a family of product objects - simple or complex. 

–     Builder returns the product as a final step, but as far as the Abstract Factory is concerned, the product gets returned immediately. 

?      Builder often builds a Composite.


Structural Design Patterns:

?      Structural design patterns ease the design by identifying a simple way to realize relationships between entities.

?      Patterns aim to separate a system from how its objects are created, composed, and represented. 

?      There are mainly 7 Structural Patterns as below

o  Adapter

o  Bridge

o  Composite

o  Decorator

o  Fa?ade

o  Flyweight

o  Proxy

Decorator Pattern (Structural Pattern)

?      Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. 

?      Client-specified embellishment of a core object by recursively wrapping it. 

?      Wrapping a gift, putting it in a box, and wrapping the box 

?      You want to add behavior or state to individual objects at run-time. Inheritance is not feasible because it is static and applies to an entire class.


Facade Pattern (Structural Pattern)

?      Facade pattern provides a unified interface to a set of interfaces in a system.

?      Fa?ade defines a higher-level interface that makes the subsystem easier to use. 


Proxy Pattern (Structural Pattern)

?      Provide a surrogate or placeholder for another object to control access to it. 

?      Use an extra level of indirection to support distributed, controlled, or intelligent access. 

?      Add a wrapper and delegation to protect the real component from undue complexity. 


Behavioral Design Patterns:

?      Behavioral design patterns identify common communication patterns between objects and realize these patterns.

?      Behavioral design patterns increase flexibility in carrying out the communication between objects.

?      There are mainly 11 Behavioral Patterns

o  Chain of Responsibility

o  Command

o  Interpreter

o  Iterator

o  Mediator

o  Memento

o  Observer

o  State

o  Strategy

o  Template Method

o  Visitor

Mediator Pattern (Behavioral Pattern)

?      Mediator pattern defines an object that encapsulates how a set of objects interacts.

?      Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.

Chain of Responsibility  (Behavioral Pattern)

?      Decouples the sender of the request to the receiver. The only link between sender and the receiver is the request which is sent. Based on the request data sent, the receiver is picked. This is called “data-driven”. 

?      Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. 

?      Launch-and-leave requests with a single processing pipeline that contains many possible handlers. 

?      Promotes the idea of loose coupling.


Strategy Pattern (Behavioral Pattern)

?      Strategy pattern (also known as the policy pattern) is a design pattern, whereby algorithms can be selected at runtime.

?      Intended to provide a means to define a family of algorithms, encapsulate each one as an object, and make them interchangeable. 

?      The strategy pattern lets the algorithms vary independently from clients that use them.

References:

first-five-principles-of-object-oriented-design

iOS Design Patterns

iOS Design Patterns 2

iOS Design Patterns implementation

5-reasons-why-design-thinking-can-standardized-process

Asadullah Ansari(He/Him)

Leading Development of HW/SW Platform for Vehicles ECUs - Systems Expert

8 年

Nice way putting all design patters into one place to overview without going to lost into sea :)

要查看或添加评论,请登录

Pradeep Misra的更多文章

社区洞察

其他会员也浏览了