SlideShare a Scribd company logo
Object Oriented Programming with Java
Unit No. 6: Design Patterns
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Information Technology
(UG Course: NBA Accredited)
Dr. Y.S.Deshmukh
Assistant Professor
Object Oriented Programming with Java
What is Design Pattern?:
Christopher Alexander says, "Each pattern describes a problem which occurs over and
over again in our environment, and then describes the core of the solution to that
problem, in such a way that you can use this solution a million times over, without ever
doing it the same way twice" [AIS+77, page x}. Even though Alexander was talking
about patterns in buildings and towns, what he says is true about object-oriented
design patterns. Our solutions are expressed in terms of objects and interfaces instead
of walls and doors, but at the core of both kinds of patterns is a solution to a problem
in a context.
Object Oriented Programming with Java
In general, a pattern has four essential elements:
1. The pattern name is a handle we can use to describe a design problem, its solution,
and consequences in a word or two. Naming a pattern immediately increases our
design vocabulary. It lets us design at a higher level of abstraction. Having a
vocabulary for patterns lets us talk about them with our colleagues, in our
documentation, and even to ourselves. It makes it easier to think about designs
and to communicate them and their trade-offs to others. Finding good names has
been one of the hardest parts of developing our catalog.
2. The problem describes when to apply the pattern. It explains the problem and its
context. It might describe specific design problems such as how to represent
algorithms as objects. It might describe class or object structures that are
symptomatic of an inflexible design. Sometimes the problem will include a list of
conditions that must be met before it makes sense to apply the pattern.
Object Oriented Programming with Java
In general, a pattern has four essential elements:
3. The solution describes the elements that make up the design, their relationships,
responsibilities, and collaborations. The solution doesn't describe a particular concrete
design or implementation, because a pattern is like a template that can be applied in
many different situations. Instead, the pattern provides an abstract description of a
design problem and how a general arrangement of elements (classes and objects in our
case) solves it.
4. The consequences are the results and trade-offs of applying the pattern. Though
consequences are often unvoiced when we describe design decisions, they are critical
for evaluating design alternatives and for understanding the costs and benefits of
applying the pattern. The consequences for software often concern space and time
trade-offs. They may address language and implementation issues as well. Since reuse
is often a factor in object-oriented design, the consequences of a pattern include its
impact on a system's flexibility, extensibility, or portability. Listing these consequences
explicitly helps you understand and evaluate them.
Object Oriented Programming with Java
How to Select a Design Pattern?:
With more than 20 design patterns in the catalog to choose from, it might be hard to
find the one that addresses a particular design problem, especially if the catalog is new
and unfamiliar to you. Here are several different approaches to finding the design
pattern that's right for your problem:
• Consider how design patterns solve design problems. Section 1.6 discusses how
design patterns help you find appropriate objects, determine object granularity,
specify object interfaces, and several other ways in which design patterns solve
design problems. Referring to these discussions can help guide your search for the
right pattern.
• Scan Intent sections. Lists the Intent sections from all the patterns in the catalog.
Read through each pattern's intent to find one or more that sound relevant to your
problem. You can use the classification scheme to narrow your search.
Object Oriented Programming with Java
How to Select a Design Pattern?:
• Study how patterns interrelate. Figure shows relationships between design patterns
graphically. Studying these relationships can help direct you to the right pattern or
group of patterns.
• Study patterns of like purpose. The catalog has three chapters, one for creational
patterns, another for structural patterns, and a third for behavioral patterns. Each
chapter starts off with introductory comments on the patterns and concludes with a
section that compares and contrasts them. These sections give you insight into the
similarities and differences between patterns of like purpose.
• Examine a cause of redesign. Look at the causes of redesign. Then look at the
patterns that help you avoid the causes of redesign.
• Consider what should be variable in your design. This approach is the opposite of
focusing on the causes of redesign. Instead of considering what might force a
change to a design, consider what you want to be able to change without redesign.
The focus here is on encapsulating the concept that varies, a theme of many design
patterns.
Object Oriented Programming with Java
How to Use a Design Pattern?:
Once you've picked a design pattern, how do you use it? Here's a step-by-step
approach to applying a design pattern effectively:
1. Read the pattern once through for an overview. Pay particular attention to the
Applicability and Consequences sections to ensure the pattern is right for your
problem.
2. Go back and study the Structure, Participants, and Collaborations sections. Make
sure you understand the classes and objects in the pattern and how they relate to
one another.
3. Look at the Sample Code section to see a concrete example of the pattern in code.
Studying the code helps you learn how to implement the pattern.
4. Choose names for pattern participants that are meaningful in the application
context. The names for participants in design patterns are usually too abstract to
appear directly in an application. Nevertheless, it's useful to incorporate the
participant name into the name that appears in the application. That helps make
the pattern more explicit in the implementation. For example, if you use the
Strategy pattern for a text compositing algorithm, then you might have classes
SimpleLayoutStrategy or TeXLayoutStrategy.
Object Oriented Programming with Java
How to Use a Design Pattern?:
Once you've picked a design pattern, how do you use it? Here's a step-by-step
approach to applying a design pattern effectively:
5. Define the classes. Declare their interfaces, establish their inheritance relationships,
and define the instance variables that represent data and object references. Identify
existing classes in your application that the pattern will affect, and modify them
accordingly.
6. Define application-specific names for operations in the pattern. Here again, the
names generally depend on the application. Use the responsibilities and collaborations
associated with each operation as a guide. Also, be consistent in your naming
conventions. For example, you might use the "Create-" prefix consistently to denote a
factory method
7. Implement the operations to carry out the responsibilities and collaborations in the
pattern. The Implementation section offers hints to guide you in the implementation.
The examples in the Sample Code section can help as well.
Object Oriented Programming with Java
Purpose Design Pattern Aspect(s) That Can Vary
Creational Abstract Factory families of product objects
Builder how a composite object gets created
Factory Method subclass of object that is instantiated
Prototype class of object that is instantiated
Singleton the sole instance of a class
Structural Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
interface to an object
implementation of an object
structure and composition of an object
responsibilities of an object without sub classing
interface to a subsystem
storage costs of objects
how an object is accessed; its location
Object Oriented Programming with Java
Purpose Design Pattern Aspect(s) That Can Vary
Behavioral Chain of
Responsibility
Command
Interpreter
Iterator
Mediator
Memento
Observer
State
Strategy
Template Method
Visitor
object that can fulfill a request
when and how a request is fulfilled
grammar and interpretation of a language
how an aggregate's elements are accessed, traversed
how and which objects interact with each other
what private information is stored outside an object, and when
number of objects that depend on another object; how the
dependent objects stay up to date
states of an object
an algorithm
steps of an algorithm
operations that can be applied to object(s) without changing
their class(es
Object Oriented Programming with Java
Object Oriented Programming with Java
SINGLETON Design Pattern:
Intent:
Ensure a class only has one instance, and provide a global point of access to it.
Motivation :
It's important for some classes to have exactly one instance. Although there can be many printers in a system,
there should be only one printer spooler. There should be only one file system and one window manager. A
digital filter will have one A/D converter. An accounting system will be dedicated to serving one company.
How do we ensure that a class has only one instance and that the instance is easily accessible? A global
variable makes an object accessible, but it doesn't keep you from instantiating multiple objects.
A better solution is to make the class it self responsible for keeping track of its sole instance.
The class can ensure that no other instance can be created (by intercepting requests to create new objects),
and it can provide a way to access the instance.
This is the Singleton pattern.
Applicability Use the Singleton pattern when
• there must be exactly one instance of a class, and it must be accessible to clients from a well-known access
point.
• when the sole instance should be extensible by sub classing, and clients should be able to use an extended
instance without modifying their code.
Object Oriented Programming with Java
ADAPTER Design Pattern:
Intent:
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that
couldn't otherwise because of incompatible interfaces.
Motivation :
Sometimes a toolkit class that's designed for reuse isn't reusable only because its interface doesn't match the
domain-specific interface an application requires. Consider for example a drawing editor that lets users draw
and arrange graphical elements (lines, polygons, text, etc.) into pictures and diagrams. The drawing editor's
key abstraction is the graphical object, which has an editable shape and can draw itself. The interface for
graphical objects is defined by an abstract class called Shape. The editor defines a subclass of Shape for each
kind of graphical object: a Line Shape class for lines, a Polygon Shape class for polygons, and so forth.
Applicability Use the Adapter pattern when
Use the Adapter pattern when
• you want to use an existing class, and its interface does not match the one you need.
• you want to create a reusable class that cooperates with unrelated or unfore-seen classes, that is, classes
that don't necessarily have compatible interfaces.
• (object adapter only) you need to use several existing subclasses, but it's im-practical to adapt their
interface by sub classing every one. An object adapter can adapt the interface of its parent class.
Object Oriented Programming with Java
ITERATOR Design Pattern:
Intent:
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying
representation
Motivation :
An aggregate object such as a list should give you a way to access its elements without exposing its internal
structure. Moreover, you might want to traverse the list in different ways, depending on what you want to
accomplish. But you probably don't want to bloat the List interface with operations for different traversals,
even if you could anticipate the ones you will need. You might also need to have more than one traversal
pending on the same list
Applicability Use the Iterator pattern when
Use the Iterator pattern
• to access an aggregate object's contents without exposing its internal representation.
• to support multiple traversals of aggregate objects.
• to provide a uniform interface for traversing different aggregate structures (that is, to support polymorphic
iteration).
Object Oriented Programming with Java
Thank You

More Related Content

Similar to Unit No 6 Design Patterns.pptx

Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
jinaldesailive
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
Sanae BEKKAR
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Luis Valencia
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
Faizan Haider
 
The I in PRIMM - Code Comprehension and Questioning
The I in PRIMM - Code Comprehension and QuestioningThe I in PRIMM - Code Comprehension and Questioning
The I in PRIMM - Code Comprehension and Questioning
Sue Sentance
 
12266422.ppt
12266422.ppt12266422.ppt
12266422.ppt
CSEC5
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Dr. C.V. Suresh Babu
 
Object Oriented Approach for Software Development
Object Oriented Approach for Software DevelopmentObject Oriented Approach for Software Development
Object Oriented Approach for Software Development
Rishabh Soni
 
010821+presentation+oti.ppt
010821+presentation+oti.ppt010821+presentation+oti.ppt
010821+presentation+oti.ppt
Yann-Gaël Guéhéneuc
 
OOM Unit I - III.pdf
OOM Unit I - III.pdfOOM Unit I - III.pdf
OOM Unit I - III.pdf
ShaikRafikhan1
 
Cse 6007 fall2012
Cse 6007 fall2012Cse 6007 fall2012
Cse 6007 fall2012rhrashel
 
Design pattern and their application
Design pattern and their applicationDesign pattern and their application
Design pattern and their application
Hiệp Tiến
 
Applying design patterns
Applying design patternsApplying design patterns
Applying design patterns
YogeshwaranT
 
DP PPTS by BK.pptx
DP PPTS by BK.pptxDP PPTS by BK.pptx
DP PPTS by BK.pptx
chandrasenareddychan
 
Design pattern
Design patternDesign pattern
Design pattern
Ramakrishna kapa
 
Design patterns
Design patternsDesign patterns
Design patterns
Ahmed Elharouny
 
Cs690 object oriented_software_engineering_team01_ report
Cs690 object oriented_software_engineering_team01_ reportCs690 object oriented_software_engineering_team01_ report
Cs690 object oriented_software_engineering_team01_ report
Khushboo Wadhwani
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur University
Shubham Narkhede
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
RushikeshChikane1
 

Similar to Unit No 6 Design Patterns.pptx (20)

Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 
The I in PRIMM - Code Comprehension and Questioning
The I in PRIMM - Code Comprehension and QuestioningThe I in PRIMM - Code Comprehension and Questioning
The I in PRIMM - Code Comprehension and Questioning
 
12266422.ppt
12266422.ppt12266422.ppt
12266422.ppt
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
Object Oriented Approach for Software Development
Object Oriented Approach for Software DevelopmentObject Oriented Approach for Software Development
Object Oriented Approach for Software Development
 
010821+presentation+oti.ppt
010821+presentation+oti.ppt010821+presentation+oti.ppt
010821+presentation+oti.ppt
 
OOM Unit I - III.pdf
OOM Unit I - III.pdfOOM Unit I - III.pdf
OOM Unit I - III.pdf
 
Cse 6007 fall2012
Cse 6007 fall2012Cse 6007 fall2012
Cse 6007 fall2012
 
Design pattern and their application
Design pattern and their applicationDesign pattern and their application
Design pattern and their application
 
Applying design patterns
Applying design patternsApplying design patterns
Applying design patterns
 
DP PPTS by BK.pptx
DP PPTS by BK.pptxDP PPTS by BK.pptx
DP PPTS by BK.pptx
 
Design pattern
Design patternDesign pattern
Design pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Cs690 object oriented_software_engineering_team01_ report
Cs690 object oriented_software_engineering_team01_ reportCs690 object oriented_software_engineering_team01_ report
Cs690 object oriented_software_engineering_team01_ report
 
Patterns Overview
Patterns OverviewPatterns Overview
Patterns Overview
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur University
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 

More from DrYogeshDeshmukh1

Unit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptxUnit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptx
DrYogeshDeshmukh1
 
Unit No 5 Files and Database Connectivity.pptx
Unit No 5 Files and Database Connectivity.pptxUnit No 5 Files and Database Connectivity.pptx
Unit No 5 Files and Database Connectivity.pptx
DrYogeshDeshmukh1
 
Unit No 4 Exception Handling and Multithreading.pptx
Unit No 4 Exception Handling and Multithreading.pptxUnit No 4 Exception Handling and Multithreading.pptx
Unit No 4 Exception Handling and Multithreading.pptx
DrYogeshDeshmukh1
 
Unit No 3 Inheritance annd Polymorphism.pptx
Unit No 3 Inheritance annd Polymorphism.pptxUnit No 3 Inheritance annd Polymorphism.pptx
Unit No 3 Inheritance annd Polymorphism.pptx
DrYogeshDeshmukh1
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
DrYogeshDeshmukh1
 
Unit 6 Uncertainty.pptx
Unit 6 Uncertainty.pptxUnit 6 Uncertainty.pptx
Unit 6 Uncertainty.pptx
DrYogeshDeshmukh1
 
Unit 5 Introduction to Planning and ANN.pptx
Unit 5 Introduction to Planning and ANN.pptxUnit 5 Introduction to Planning and ANN.pptx
Unit 5 Introduction to Planning and ANN.pptx
DrYogeshDeshmukh1
 
Unit 4 Knowledge Representation.pptx
Unit 4 Knowledge Representation.pptxUnit 4 Knowledge Representation.pptx
Unit 4 Knowledge Representation.pptx
DrYogeshDeshmukh1
 
Unit 3 Informed Search Strategies.pptx
Unit  3 Informed Search Strategies.pptxUnit  3 Informed Search Strategies.pptx
Unit 3 Informed Search Strategies.pptx
DrYogeshDeshmukh1
 
DAA Unit 1 Part 1.pptx
DAA Unit 1 Part 1.pptxDAA Unit 1 Part 1.pptx
DAA Unit 1 Part 1.pptx
DrYogeshDeshmukh1
 
AI Overview.pptx
AI Overview.pptxAI Overview.pptx
AI Overview.pptx
DrYogeshDeshmukh1
 
Unit 2 Uninformed Search Strategies.pptx
Unit  2 Uninformed Search Strategies.pptxUnit  2 Uninformed Search Strategies.pptx
Unit 2 Uninformed Search Strategies.pptx
DrYogeshDeshmukh1
 
Unit 1 Fundamentals of Artificial Intelligence-Part II.pptx
Unit 1  Fundamentals of Artificial Intelligence-Part II.pptxUnit 1  Fundamentals of Artificial Intelligence-Part II.pptx
Unit 1 Fundamentals of Artificial Intelligence-Part II.pptx
DrYogeshDeshmukh1
 
Unit 1 Fundamentals of Artificial Intelligence-Part I.pptx
Unit 1  Fundamentals of Artificial Intelligence-Part I.pptxUnit 1  Fundamentals of Artificial Intelligence-Part I.pptx
Unit 1 Fundamentals of Artificial Intelligence-Part I.pptx
DrYogeshDeshmukh1
 

More from DrYogeshDeshmukh1 (14)

Unit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptxUnit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptx
 
Unit No 5 Files and Database Connectivity.pptx
Unit No 5 Files and Database Connectivity.pptxUnit No 5 Files and Database Connectivity.pptx
Unit No 5 Files and Database Connectivity.pptx
 
Unit No 4 Exception Handling and Multithreading.pptx
Unit No 4 Exception Handling and Multithreading.pptxUnit No 4 Exception Handling and Multithreading.pptx
Unit No 4 Exception Handling and Multithreading.pptx
 
Unit No 3 Inheritance annd Polymorphism.pptx
Unit No 3 Inheritance annd Polymorphism.pptxUnit No 3 Inheritance annd Polymorphism.pptx
Unit No 3 Inheritance annd Polymorphism.pptx
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
 
Unit 6 Uncertainty.pptx
Unit 6 Uncertainty.pptxUnit 6 Uncertainty.pptx
Unit 6 Uncertainty.pptx
 
Unit 5 Introduction to Planning and ANN.pptx
Unit 5 Introduction to Planning and ANN.pptxUnit 5 Introduction to Planning and ANN.pptx
Unit 5 Introduction to Planning and ANN.pptx
 
Unit 4 Knowledge Representation.pptx
Unit 4 Knowledge Representation.pptxUnit 4 Knowledge Representation.pptx
Unit 4 Knowledge Representation.pptx
 
Unit 3 Informed Search Strategies.pptx
Unit  3 Informed Search Strategies.pptxUnit  3 Informed Search Strategies.pptx
Unit 3 Informed Search Strategies.pptx
 
DAA Unit 1 Part 1.pptx
DAA Unit 1 Part 1.pptxDAA Unit 1 Part 1.pptx
DAA Unit 1 Part 1.pptx
 
AI Overview.pptx
AI Overview.pptxAI Overview.pptx
AI Overview.pptx
 
Unit 2 Uninformed Search Strategies.pptx
Unit  2 Uninformed Search Strategies.pptxUnit  2 Uninformed Search Strategies.pptx
Unit 2 Uninformed Search Strategies.pptx
 
Unit 1 Fundamentals of Artificial Intelligence-Part II.pptx
Unit 1  Fundamentals of Artificial Intelligence-Part II.pptxUnit 1  Fundamentals of Artificial Intelligence-Part II.pptx
Unit 1 Fundamentals of Artificial Intelligence-Part II.pptx
 
Unit 1 Fundamentals of Artificial Intelligence-Part I.pptx
Unit 1  Fundamentals of Artificial Intelligence-Part I.pptxUnit 1  Fundamentals of Artificial Intelligence-Part I.pptx
Unit 1 Fundamentals of Artificial Intelligence-Part I.pptx
 

Recently uploaded

Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 

Recently uploaded (20)

Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 

Unit No 6 Design Patterns.pptx

  • 1. Object Oriented Programming with Java Unit No. 6: Design Patterns Sanjivani Rural Education Society’s Sanjivani College of Engineering, Kopargaon-423603 (An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune) NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified Department of Information Technology (UG Course: NBA Accredited) Dr. Y.S.Deshmukh Assistant Professor
  • 2. Object Oriented Programming with Java What is Design Pattern?: Christopher Alexander says, "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice" [AIS+77, page x}. Even though Alexander was talking about patterns in buildings and towns, what he says is true about object-oriented design patterns. Our solutions are expressed in terms of objects and interfaces instead of walls and doors, but at the core of both kinds of patterns is a solution to a problem in a context.
  • 3. Object Oriented Programming with Java In general, a pattern has four essential elements: 1. The pattern name is a handle we can use to describe a design problem, its solution, and consequences in a word or two. Naming a pattern immediately increases our design vocabulary. It lets us design at a higher level of abstraction. Having a vocabulary for patterns lets us talk about them with our colleagues, in our documentation, and even to ourselves. It makes it easier to think about designs and to communicate them and their trade-offs to others. Finding good names has been one of the hardest parts of developing our catalog. 2. The problem describes when to apply the pattern. It explains the problem and its context. It might describe specific design problems such as how to represent algorithms as objects. It might describe class or object structures that are symptomatic of an inflexible design. Sometimes the problem will include a list of conditions that must be met before it makes sense to apply the pattern.
  • 4. Object Oriented Programming with Java In general, a pattern has four essential elements: 3. The solution describes the elements that make up the design, their relationships, responsibilities, and collaborations. The solution doesn't describe a particular concrete design or implementation, because a pattern is like a template that can be applied in many different situations. Instead, the pattern provides an abstract description of a design problem and how a general arrangement of elements (classes and objects in our case) solves it. 4. The consequences are the results and trade-offs of applying the pattern. Though consequences are often unvoiced when we describe design decisions, they are critical for evaluating design alternatives and for understanding the costs and benefits of applying the pattern. The consequences for software often concern space and time trade-offs. They may address language and implementation issues as well. Since reuse is often a factor in object-oriented design, the consequences of a pattern include its impact on a system's flexibility, extensibility, or portability. Listing these consequences explicitly helps you understand and evaluate them.
  • 5. Object Oriented Programming with Java How to Select a Design Pattern?: With more than 20 design patterns in the catalog to choose from, it might be hard to find the one that addresses a particular design problem, especially if the catalog is new and unfamiliar to you. Here are several different approaches to finding the design pattern that's right for your problem: • Consider how design patterns solve design problems. Section 1.6 discusses how design patterns help you find appropriate objects, determine object granularity, specify object interfaces, and several other ways in which design patterns solve design problems. Referring to these discussions can help guide your search for the right pattern. • Scan Intent sections. Lists the Intent sections from all the patterns in the catalog. Read through each pattern's intent to find one or more that sound relevant to your problem. You can use the classification scheme to narrow your search.
  • 6. Object Oriented Programming with Java How to Select a Design Pattern?: • Study how patterns interrelate. Figure shows relationships between design patterns graphically. Studying these relationships can help direct you to the right pattern or group of patterns. • Study patterns of like purpose. The catalog has three chapters, one for creational patterns, another for structural patterns, and a third for behavioral patterns. Each chapter starts off with introductory comments on the patterns and concludes with a section that compares and contrasts them. These sections give you insight into the similarities and differences between patterns of like purpose. • Examine a cause of redesign. Look at the causes of redesign. Then look at the patterns that help you avoid the causes of redesign. • Consider what should be variable in your design. This approach is the opposite of focusing on the causes of redesign. Instead of considering what might force a change to a design, consider what you want to be able to change without redesign. The focus here is on encapsulating the concept that varies, a theme of many design patterns.
  • 7. Object Oriented Programming with Java How to Use a Design Pattern?: Once you've picked a design pattern, how do you use it? Here's a step-by-step approach to applying a design pattern effectively: 1. Read the pattern once through for an overview. Pay particular attention to the Applicability and Consequences sections to ensure the pattern is right for your problem. 2. Go back and study the Structure, Participants, and Collaborations sections. Make sure you understand the classes and objects in the pattern and how they relate to one another. 3. Look at the Sample Code section to see a concrete example of the pattern in code. Studying the code helps you learn how to implement the pattern. 4. Choose names for pattern participants that are meaningful in the application context. The names for participants in design patterns are usually too abstract to appear directly in an application. Nevertheless, it's useful to incorporate the participant name into the name that appears in the application. That helps make the pattern more explicit in the implementation. For example, if you use the Strategy pattern for a text compositing algorithm, then you might have classes SimpleLayoutStrategy or TeXLayoutStrategy.
  • 8. Object Oriented Programming with Java How to Use a Design Pattern?: Once you've picked a design pattern, how do you use it? Here's a step-by-step approach to applying a design pattern effectively: 5. Define the classes. Declare their interfaces, establish their inheritance relationships, and define the instance variables that represent data and object references. Identify existing classes in your application that the pattern will affect, and modify them accordingly. 6. Define application-specific names for operations in the pattern. Here again, the names generally depend on the application. Use the responsibilities and collaborations associated with each operation as a guide. Also, be consistent in your naming conventions. For example, you might use the "Create-" prefix consistently to denote a factory method 7. Implement the operations to carry out the responsibilities and collaborations in the pattern. The Implementation section offers hints to guide you in the implementation. The examples in the Sample Code section can help as well.
  • 9. Object Oriented Programming with Java Purpose Design Pattern Aspect(s) That Can Vary Creational Abstract Factory families of product objects Builder how a composite object gets created Factory Method subclass of object that is instantiated Prototype class of object that is instantiated Singleton the sole instance of a class Structural Adapter Bridge Composite Decorator Facade Flyweight Proxy interface to an object implementation of an object structure and composition of an object responsibilities of an object without sub classing interface to a subsystem storage costs of objects how an object is accessed; its location
  • 10. Object Oriented Programming with Java Purpose Design Pattern Aspect(s) That Can Vary Behavioral Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor object that can fulfill a request when and how a request is fulfilled grammar and interpretation of a language how an aggregate's elements are accessed, traversed how and which objects interact with each other what private information is stored outside an object, and when number of objects that depend on another object; how the dependent objects stay up to date states of an object an algorithm steps of an algorithm operations that can be applied to object(s) without changing their class(es
  • 12. Object Oriented Programming with Java SINGLETON Design Pattern: Intent: Ensure a class only has one instance, and provide a global point of access to it. Motivation : It's important for some classes to have exactly one instance. Although there can be many printers in a system, there should be only one printer spooler. There should be only one file system and one window manager. A digital filter will have one A/D converter. An accounting system will be dedicated to serving one company. How do we ensure that a class has only one instance and that the instance is easily accessible? A global variable makes an object accessible, but it doesn't keep you from instantiating multiple objects. A better solution is to make the class it self responsible for keeping track of its sole instance. The class can ensure that no other instance can be created (by intercepting requests to create new objects), and it can provide a way to access the instance. This is the Singleton pattern. Applicability Use the Singleton pattern when • there must be exactly one instance of a class, and it must be accessible to clients from a well-known access point. • when the sole instance should be extensible by sub classing, and clients should be able to use an extended instance without modifying their code.
  • 13. Object Oriented Programming with Java ADAPTER Design Pattern: Intent: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Motivation : Sometimes a toolkit class that's designed for reuse isn't reusable only because its interface doesn't match the domain-specific interface an application requires. Consider for example a drawing editor that lets users draw and arrange graphical elements (lines, polygons, text, etc.) into pictures and diagrams. The drawing editor's key abstraction is the graphical object, which has an editable shape and can draw itself. The interface for graphical objects is defined by an abstract class called Shape. The editor defines a subclass of Shape for each kind of graphical object: a Line Shape class for lines, a Polygon Shape class for polygons, and so forth. Applicability Use the Adapter pattern when Use the Adapter pattern when • you want to use an existing class, and its interface does not match the one you need. • you want to create a reusable class that cooperates with unrelated or unfore-seen classes, that is, classes that don't necessarily have compatible interfaces. • (object adapter only) you need to use several existing subclasses, but it's im-practical to adapt their interface by sub classing every one. An object adapter can adapt the interface of its parent class.
  • 14. Object Oriented Programming with Java ITERATOR Design Pattern: Intent: Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation Motivation : An aggregate object such as a list should give you a way to access its elements without exposing its internal structure. Moreover, you might want to traverse the list in different ways, depending on what you want to accomplish. But you probably don't want to bloat the List interface with operations for different traversals, even if you could anticipate the ones you will need. You might also need to have more than one traversal pending on the same list Applicability Use the Iterator pattern when Use the Iterator pattern • to access an aggregate object's contents without exposing its internal representation. • to support multiple traversals of aggregate objects. • to provide a uniform interface for traversing different aggregate structures (that is, to support polymorphic iteration).
  • 15. Object Oriented Programming with Java Thank You