Copyright W. Howden1 Lecture 6: Design Evaluation and Intro to OO Design Patterns.
Design Patterns Lecture
-
Upload
deepeshkumarpal5194 -
Category
Documents
-
view
33 -
download
0
description
Transcript of Design Patterns Lecture
![Page 1: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/1.jpg)
Design Patterns Introduction
![Page 2: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/2.jpg)
What is a Design Pattern?
A technique to repeat designer success.
Borrowed from Civil and Electrical Engineering domains.
A (Problem, Solution) pair.
![Page 3: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/3.jpg)
How Patterns are used? Design Problem. Solution. Implementation details.
Reduce gap
Design Implementation
Designer
Programmer
Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design patterns: elements of reusable object-oriented software. 1995.
Buschmann, F., Meunier, R., Rohnert, H., Sommerlad, P., Stal, M.: Pattern-oriented software architecture: a system of patterns. 2002.
![Page 4: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/4.jpg)
Design patterns you have already seen
Encapsulation (Data Hiding) Subclassing (Inheritance) Iteration Exceptions
![Page 5: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/5.jpg)
Encapsulation pattern Problem: Exposed fields are directly
manipulated from outside, leading to undesirable dependences that prevent changing the implementation.
Solution: Hide some components, permitting only stylized access to the object.
![Page 6: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/6.jpg)
Exception pattern Problem: Code is cluttered with error-
handling code.
Solution: Errors occurring in one part of the code should often be handled elsewhere. Use language structures for throwing and catching exceptions.
![Page 7: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/7.jpg)
Derived Conclusion Patterns are Programming language features.
Programming languages are moving towards Design.
Many patterns are being implemented in programming languages.
![Page 8: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/8.jpg)
Pattern Categories Creational Patterns concern the process of
object creation.
Structural Patterns concern with integration and composition of classes and objects.
Behavioral Patterns concern with class or object communication.
![Page 9: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/9.jpg)
What is the addressing Quality Attribute?
Modifiability, Exchangeability, Reusability, Extensibility, Maintainability.
What properties these patterns provide?
More general code for better Reusability.
Redundant code elimination for better Maintainability.
![Page 10: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/10.jpg)
Design pattern example
![Page 11: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/11.jpg)
Some examples of Design Patterns
![Page 12: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/12.jpg)
Template for discussion Non-software example. Pattern intent. Software counterpart example.
Non-software examples are derived from paper
& PPT – “Non-software examples of software
design patterns” (OOPSLA 97).
![Page 13: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/13.jpg)
Facade (Non software example)
Provide a unified
interface to a set
of interfaces in a
subsystem.
![Page 14: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/14.jpg)
Facade (Software counterpart)
![Page 15: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/15.jpg)
Flyweight (Non software example)
Use sharing to
support large
numbers of fine-
grained objects
efficiently
![Page 16: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/16.jpg)
Flyweight (Software counterpart)
Memory
![Page 17: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/17.jpg)
Chain of Responsibility (Non software example)
Chain the
receiving objects
and pass the
request along the
chain until an
object handles it.
![Page 18: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/18.jpg)
Chain of Responsibility (Software counterpart)
Login page
Password checking
Balance statement
Internet
![Page 19: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/19.jpg)
Memento (Non software example)
Externalize
object’s state so
that object can be
restored to this
state later.
![Page 20: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/20.jpg)
Memento (Software counterpart)
![Page 21: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/21.jpg)
Observer (Non software example)
When an object
changes its state,
all its dependants
are notified.
![Page 22: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/22.jpg)
Observer (Software counterpart)
Internet
Cricinfo Server
![Page 23: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/23.jpg)
Adapter (Non software example)
Convert the
interface of a
class into another
Interface clients
expect.
![Page 24: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/24.jpg)
Adapter (Software counterpart)
Java module C++ moduleJava Native
Interface (JNI)
![Page 25: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/25.jpg)
Builder (Non software example)
Separate the construction
process of a complex object
from its representation so
that the same construction
Process can create different
representations.
![Page 26: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/26.jpg)
Builder (Software counterpart)
Lexicalanalysis
Syntax analysis
Semanticanalysis
Intermediate code
Interpretation
Compiler process
Java Lexer
Java Parser
Semanticanalysis
Java byte code
JVM
Java Compiler
Python Lexer
Python Parser
Semanticanalysis
Python byte code
PVM
Python Compiler
![Page 27: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/27.jpg)
Iterator (Non software example)
Provide a way to
access the
elements of a set
sequentially.
![Page 28: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/28.jpg)
Iterator (Software counterpart)
![Page 29: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/29.jpg)
Interpreter (Non software example)
Interpreter interprets
the sentences in a
language based
on its grammar.
![Page 30: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/30.jpg)
Interpreter (Software counterpart)
:-) is interpreted as
:-( is interpreted as
In Gtalk/Yahoo messengers
![Page 31: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/31.jpg)
Broker (Non software example)
Broker component is
responsible for
coordinating
communication
between clients and
remote servers.
![Page 32: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/32.jpg)
Broker (Software counterpart)
![Page 33: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/33.jpg)
Publisher-Subscriber (Non software example)
Publishers register
themselves to a
broker and
subscribers discover
publisher from broker.
![Page 34: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/34.jpg)
Publisher-Subscriber (Software counterpart)
Forums (e.g. movie forums)
![Page 35: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/35.jpg)
Proxy (Non software example)
Provide a surrogate or
placeholder for
another object to
control access to it.
![Page 36: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/36.jpg)
Proxy (Software counterpart)
![Page 37: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/37.jpg)
Strategy (Non software example)
A Strategy defines a set of algorithms that can be
used interchangeably.
![Page 38: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/38.jpg)
Strategy (Software counterpart)
Multiple
interchangeable
weapons available to
attack an enemy.
![Page 39: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/39.jpg)
Mediator (Non software example)
Loose coupling
between colleague
objects is achieved by
having colleagues
communicate with the
Mediator, rather than
one another.
![Page 40: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/40.jpg)
Mediator (Software counterpart)
Gtalk Server
![Page 41: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/41.jpg)
Master-Slave (Non software example)
Master component
distributes work to
identical slave
components and
computes a final
result from the results
when the slaves
return.
![Page 42: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/42.jpg)
Master-Slave (Software counterpart)
Movie players High-resolution Game players
Graphics partitioning
![Page 43: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/43.jpg)
Layers (Software example)
Layers structure applications whose dominant
characteristic is a mix of low- and high- level issues.
![Page 44: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/44.jpg)
MVC (Software example)
MVC structures interactive applications.
![Page 45: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/45.jpg)
Microkernel (Software example)
Microkernel separates the variant and non-variant
parts of a product-line application.
![Page 46: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/46.jpg)
Reflection (Software example)
Reflection pattern provides a mechanism for changing
structure and behavior of a system dynamically.
![Page 47: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/47.jpg)
State (Software example)An object alters its
behavior when its
internal state
changes.
![Page 48: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/48.jpg)
Template Method (Software example)
Define the skeleton of an
algorithm in an operation,
deferring some steps to
subclasses.
Event handling in Java GUI
components is unimplemented.
![Page 49: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/49.jpg)
Observer example
![Page 50: Design Patterns Lecture](https://reader033.fdocuments.in/reader033/viewer/2022061603/55cf8e96550346703b93a88f/html5/thumbnails/50.jpg)
04/21/23 52