Lecture 1 Software Design Patterns Update
Lecture 1 Software Design Patterns Update
Lecture 1
Contents
● What is a Design Pattern?
● Elements of the Design Pattern
● What design patterns are NOT
● Describing Design Patterns
● Types of Design Patterns
● When to use Design Patterns
● Benefits of Design Patterns
● Draw backs to Design Patterns
● How to Select a Design Pattern
What is a Design Pattern?
● A Pattern must:
○ Solve a problem and be useful
○ Have a context and can describe where the solution can be
used
○ Recur in relevant situations
○ Provide sufficient understanding to tailor the solution
○ Have a name and be referenced consistently
Elements of Design Patterns
● They are:
○ “Descriptions of communicating objects and classes that
are customized to solve a general design problem in a
particular context.”
Describing Design Patterns
● Creational patterns:
○ Deal with creating, initializing, and configuring classes
and objects
● Structural patterns:
○ Deal Composition of classes or objects
○ Implementation of Interfaces, classes and objects.
● Behavioural patterns:
○ Behavioural patterns characterize the ways in which
classes or objects interact.
○ How they distribute responsibility
Creational Patterns
● Abstract Factory:
○ Provide an interface for building related or dependant objects
without specifying their concrete class.
● Builder:
○ Separate the construction of a complex object from its
representation so that same construction process can create
different representations.
● Factory Method:
○ Define an interface for creating an object, but let subclass decide
which class to instantiate. Factory Method lets a class defer
instantiation to subclass.
Creational Patterns (cont.)
● Prototype:
○ Specify the kinds of objects to create using a prototypical instance,
and create new objects by copying this prototype.
● Singleton:
○ Ensure a class only has one instance, and provide a global point of
access to it.
Structural Patterns
● Adapter:
○ Convert the interface of a class into another interface that clients
expect. Adapter lets classes work together that couldn’t otherwise
because of the incompatible interfaces.
● Bridge:
○ Decouple an abstraction from its implementation so that the two
can vary independently.
● Composite:
○ Compose objects into tree structures to represent part-whole
hierarchies. Composite lets client treat individual objects and
compositions of objects uniformly.
● Decorator:
○ Attach additional responsibilities to an object dynamically.
Decorators provide a higher-level interface that makes the
subsystem easier to use.
Structural Patterns (cont.)
● Facade:
○ Simplifies the interface for a subsystem
● Flyweight:
○ Many fine-grained objects shared efficiently.
● Proxy:
○ Provide a placeholder for another object to control access to it.
Behavioural Patterns
● Chain of Responsibility:
○ Request delegated to the responsible service provider
● Command:
○ Encapsulate a request as an object, thereby letting you
parameterize clients with different requests, queue or log requests,
and support undoable operations.
● Iterator:
○ Provide a way to access the elements of an aggregate object
sequentially without exposing its underlying representation.
● Interpreter:
○ Language interpreter for a small grammar
● Mediator:
○ Coordinates interactions between its associates
● Memento:
○ Snapshot captures and restores object states privately
Behavioral Patterns (cont.)
● Observer:
○ Dependents update automatically when subject changes
● State:
○ Object whose behaviour depends on its state
● Strategy:
○ Abstraction for selecting one of many algorithms
● Template Method:
○ Algorithm with some steps supplied by a derived class
● Visitor:
○ Represent an operation to be performed on the elements of an
object structure. Visitor lets you define a new operation without
changing the classes of the elements on which it operates.
Design Pattern Space
Purpose
Creational Structural Behavioral
Scope Class Factory method Adapter (class) Interpreter
Template method
Object Abstract factory Adapter (object) Chain of
Builder Bridge responsibility
Prototype Composite Command
Singleton Decorator Iterator
Façade Mediator
Flyweight Memento
Proxy Observer
State
Strategy
Visitor
Categorization Terms
● Class:: Creational
○ Abstracts how classes are instantiated
● Class:: Structural
○ Use inheritance and composition for structural changes
and collaboration
● Class:: Behavioural
○ Captures how classes cooperate with each other to
share responsibilities.
Object Scope
● Object:: Creational
○ Abstracts how sets of objects are created
● Object:: Structural
○ Describe ways to assemble objects to realize new
functionality
○ Achieved through polymorphism
○ Not possible with static class composition
● Object:: Behavioural
○ Describes how a group of peer objects cooperate to
perform a task that can be carried out by itself.
When to Use Patterns