Lecture Notes: IV B. Tech I Semester (JNTUH-R13)
Lecture Notes: IV B. Tech I Semester (JNTUH-R13)
asia
LECTURE NOTES
ON
DESIGN PATTERNS
INFORMATION TECHNOLOGY
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
CONTENTS
UNIT-I
Introduction:
1. What is a design pattern?
2. Design patterns in Smalltalk MVC
3. Describing Design Patterns
4. The Catalog of Design Patterns
5. Organizing the Catalog
6. How Design Patterns Solve Design Problems
7. How to Select a Design Pattern
8. How to use a Design Pattern.
UNIT-II
A Case Study:
1. Designing a Document Editor Design Problems,
2. Document Structure
3. Formatting
4. Embellishing the User Interface
5. Supporting Multiple Look-and Feel Standards
6. Supporting Multiple Window Systems,
7. User Operations Spelling Checking and Hyphenation,
8. Summary.
9. Creational Patterns: Abstract Factory
10. Builder
11. Factory Method
12. Prototype
13. Singleton
14. Discussion of Creational Patterns
UNIT-III
Structural Pattern Part-I :
1. Adapter
2. Bridge
3. Composite
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
UNIT-IV
Behavioural Patterns Part-I :
1. Chain of Responsibility
2. Command
3. Interpreter
4. Iterator
UNIT-V
Behavioural Patterns Part-II (cont’d):
1. State
2. Strategy
3. Template Method
4. Visitor
5. Discussion of Behavioral Patterns
UNIT -I
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
Introduction
What is a Design Pattern?
• Each pattern Describes a problem which occurs over and over again in our
environment ,and then describes the core of the problem
• Novelists, playwrights and other writers rarely invent new stories.
• Often ideas are reused, such as the “Tragic Hero” from Hamlet or Macbeth.
• Designers reuse solutions also, preferably the “good” ones
– Experience is what makes one an ‘expert’
• Problems are addressed without rediscovering solutions from scratch.
“My wheel is rounder.
Design Patterns are the best solutions for the re-occurring problems in the application
programming environment.
• Nearly a universal standard.
• Responsible for design pattern analysis in other areas, including GUIs.
• Mainly used in Object Oriented programming.
Design Pattern Elements
1. Pattern Name
Handle used to describe the design problem.
Increases vocabulary.
Eases design discussions.
Evaluation without implementation details.
2. Problem
Describes when to apply a pattern.
May include conditions for the pattern to be applicable.
Symptoms of an inflexible design or limitation.
3. Solution
Describes elements for the design.
Includes relationships, responsibilities, and collaborations.
Does not describe concrete designs or implementations.
A pattern is more of a template.
4. Consequences
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
Applicability:
• Applicability: What are the situations in which the design patterns can be applied?
• What are example of the poor designs that the pattern can address?
• How can recognize situations?
• Structure: Graphical representation of the classes in the pattern using a notation based
on the object Modeling Technique(OMT).
• Participants: The classes and/or objects participating in the design pattern and their
responsibilities.
Structure:
Graphical representation of the classes in the pattern using a notation based on the
object Modeling Technique(OMT).
Participants:
The classes and/or objects participating in the design pattern and their responsibilities.
Collaborations:
How the participants collaborate to carry out their responsibilities.
Consequences:
How does the pattern support its objectives?
What are the trade-offs and result of using the pattern ?
What aspect of the system structure does it let vary independently?
Implementation:
What pitfalls,hints,or techniques should be aware of when implementing the pattern ?
Are there language-specific issues?
Sample Code:
Code fragments that illustrate how might implement the pattern in c++ or Smalltalk.
Known Uses:
Examples of the pattern found in real systems.
Related Patterns:
What design patterns are closely related to this one? What are the imp differences?
With Which other patterns should this one be used?
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• Interface:
– Set of all signatures defined by an object’s operations.
– Any request matching a signature in the objects interface may be sent to the
object.
– Interfaces may contain other interfaces as subsets.
• Type:
– Denotes a particular interfaces.
– An object may have many types.
– Widely different object may share a type.
– Objects of the same type need only share parts of their interfaces.
– A subtype contains the interface of its super type.
• Dynamic binding, polymorphism.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
– An object can have many types, and objects of different classes can have the
same type.
• Class versus Interface Inheritance
– class inheritance defines an object’s implementation in terms of another
object’s implementation (code and representation sharing).
– interface inheritance (or subtyping) describes when an object can be used in
place of another.
• Many of the design patterns depend on this distinction.
• White-box reuse:
– Reuse by subclassing (class inheritance)
– Internals of parent classes are often visible to subclasses
– works statically, compile-time approach
– Inheritance breaks encapsulation
• Black-box reuse:
– Reuse by object composition
– Requires objects to have well-defined interfaces
– No internal details of objects are visible
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
Delegation:
• Two objects are involved in handling a request: a receiving object delegates
operations to its delegate.
• Makes it easy to compose behaviors at run-time and to change the way they’re
composed.
• Disadvantage:dynamic, highly parameterized software is harder to understand than
more static software.
• Delegation is a good design choice only when it simplifies more than it complicates.
• Delegation is an extreme example of object composition.
– parameterized types let you change the types that a class can use.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
– each design pattern lets some aspect of system structure vary independently of
other aspects.
• Algorithmic dependencies.
Common Causes of Redesign (cont.)
• Tight coupling.
• Extending functionality by subclassing .
• Inability to alter classes conveniently.
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
jntuworldupdates.org Specworld.in