2. Page | 1
Software Design Patterns
Summary
A design pattern is a general reusable solution to a commonly occurring problem in software
design. A design pattern is not a finished design that can be transformed directly into code instead
it is a description or template for how to solve a problem that can be used in many different
situations. Object-oriented design patterns typically show relationships and interactions between
classes or objects, without specifying the final application classes or objects that are involved. At
a higher level there are architectural patterns that are larger in scope, usually describing an overall
pattern followed by an entire system. Design patterns are a powerful tool for software developers.
Originally, design patterns were grouped in to the 3 categories: creational patterns, structural
patterns, and behavioral patterns.
Creational design patterns deal with the mechanism of object creation and trying to create the
object in such a way that they are suitable to the situation. 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. The basic form of object
creation could result in design problems or in added complexity to the design. Creational design
patterns solve this problem by somehow controlling this object creation. These design patterns
consist of 2 main ideas i.e. encapsulating knowledge about which concrete classes the system uses
and hiding the detail related to how instances of these concrete classes are created and combined.
Creational design patterns are further categorized into Object-creational patterns and Class-
creational patterns. Object-creational patterns deal with Object creation and Class-creational
patterns deal with Class-instantiation. Also that Object-creational patterns defer part of its object
creation to another object, while Class-creational patterns defer its object creation to subclasses.
There are five more patterns that are the part of the creational design patterns. These five patterns
are Abstract factory pattern, which provides an interface for creating related or dependent objects
without specifying the concrete classes of objects, Builder pattern, which separates the
construction of a complex object from its representation so that the same construction process can
create different representations, Factory method pattern, which allows a class to defer instantiation
to subclasses, Prototype pattern, which specifies the kind of object to create using a prototypical
3. Page | 2
instance, and creates new objects by cloning this prototype, Singleton pattern, which ensures that
a class only has one instance, and provides a global point of access to it.
The second type of design pattern is the structural pattern. Structural patterns provide a manner to
define relationships between classes or objects. These design patterns are all about Class and
Object composition. Structural object-patterns define ways to compose objects to obtain new
functionality. Concept of inheritance is used to compose interfaces and define ways to compose
objects to obtain new functionalities. These design patterns contains multiple parts like adapter,
bridge, composite, decorator, facade, flyweight, private class data and proxy. Adapter or Wrapper
converts the interface of a class into another interface clients expect. Adapter lets classes work
together that could not otherwise because of incompatible interfaces. Bridge decouple an
abstraction from its implementation allowing the two to vary independently. Composite compose
objects into tree structures to represent part-whole hierarchies. Composite lets clients treat
individual objects and compositions of objects uniformly. Decorator attach additional
responsibilities to an object dynamically keeping the same interface. Decorators provide a flexible
alternative to subclassing for extending functionality. Facade provide a unified interface to a set
of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem
easier to use. Front Controller provide a unified interface to a set of interfaces in a subsystem.
Front Controller defines a higher-level interface that makes the subsystem easier to use. Flyweight
use sharing to support large numbers of fine-grained objects efficiently. Proxy provide a surrogate
or placeholder for another object to control access to it.
The final type of design pattern is the behavioral pattern. Behavioral patterns define manners of
communication between classes and objects. These design patterns are all about Class's objects
communication. Behavioral patterns are those patterns that are most specifically concerned with
communication between objects. They identify common communication patterns between objects
and realize these patterns. By doing so, these patterns increase flexibility in carrying out this
communication. Behavioral patterns consists of twelve patterns that are the part of these behavioral
patterns and they are Chain of responsibility, Command, Interpreter, Iterator, Mediator, Memento,
Null Object, Observer, State, Strategy, Template method, Visitor. Chain of responsibility is a way
of passing a request between a chain of objects, Command encapsulate a command request as an
object, Interpreter provides a way to include language elements in a program, Iterator sequentially
4. Page | 3
access the elements of a collection, Mediator defines simplified communication between classes,
Memento captures and restores an object's internal state, Null Object designed to act as a default
value of an object, Observer provides 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 hold on to the exact steps of an algorithm to a subclass and Visitor defines a new
operation to a class without change