SlideShare a Scribd company logo
UNIT IV DESIGN PATTERNS
Presented By R.Krishna Prakash,
Assistant Professor/CSE,
Kongunadu College Of Engineering And Technology.
KONGUNADU COLLEGE OF ENGINEERING
AND TECHNOLOGY
(AUTONOMOUS)
UNIT IV DESIGN
PATTERNS
Design Patterns
• It’s typical solutions to common problems in software design.
• Each pattern is like a blueprint that you can customize to solve a
particular design problem in your code
Designing objects with responsibilities
• GRASP-General responsibility assignment software patterns
- GRASP is a tool that helps to master the basics of OOD and
understanding responsibilities
- A learning aid that helps to understand for OO design with
responsibilities
• RDD -Responsibility Driven Design
It’s thinking about object oriented design
Doing responsibility- creating action, initializing, controlling
and coordinating activities
Knowing responsibilities- includes knowing about private
and related data
Applying Grasp to Object Design
There are nine different GRASP patterns:
(i) Creator
(ii) Information expert
(iii) Low coupling
(iv) Controller
(v) High cohesion
(vi) Polymorphism
(vii) Pure fabrication
(viii) Indirection
(ix) Protected variations
Creator
• Its one of the common activities in object oriented system
is creation of object
• General principle is applied for the assignment of creation
responsibilities.
If B is a creator of A objects then atleast one of the following
must be true.
• B contains A
• B compositely aggregates A
• B records A
• B closely uses A
UNIT IV DESIGN PATTERNS.pptx
INFORMATION EXPERT
•Designing objects, interaction between objects are defined
about assigning responsibilities to software classes
This makes the software easier to
• Maintain
• Understand
• Extend
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
LOW COUPLING
Coupling is the measure of less strongly one element is
connected to the other elements.
Types of coupling
There are 2 types of coupling
1) Low coupling or weak coupling
2) High coupling or strong coupling
• Low coupling
An element if does not depend on too many other elements like
classes, subsystems systems it is having low coupling
• High coupling
A class with high coupling relies on many other classes.
The problems of high coupling are
• Harder to understand
• Harder to reuse
Example
Benefits for LOW Coupling
•Not affected by changes in other components
•Simple to understand
•Convenient to reuse
HIGH COHESION
•Strongly related and focused responsibilities of an
element. An element has high cohesion if it,
•Difficulties of low cohesion are
•Hard to comprehend
•Hard to reuse
•Hard to maintain
UNIT IV DESIGN PATTERNS.pptx
Functional Cohesion
(1) Very low cohesion
• A class is solely responsible for many things in different functional areas.
(2) Low cohesion
• A class has sole responsibility for a complex task in one functional area.
(3) High cohesion
• A class has moderate responsibilities in one functional area and
collaborates with others.
(4) Moderate cohesion
• A class has light weight. It is responsible for different areas logically
related to the class concept but not to each other
High cohesion is
• Easy to maintain
• Understand
• Reuse
Benefits of high cohesion are
•Clarity
•Ease of comprehension
CONTROLLER
•A controller is defined as the first object beyond the user interface
(UI) layer that is responsible for the receiving or handling a system
operation message.
UNIT IV DESIGN PATTERNS.pptx
Design patterns
Designing for visibility:
• One object to have reference of another is called visibility
Ex: getProductDescription message sent from a Register to a
product catalog means that ProductCatalog instance is
visible to register.
UNIT IV DESIGN PATTERNS.pptx
Ways of visibility: from Object A to Object B
Attribute visibility – B is an attribute of A
Parameter visibility – B is a parameter of a method of A
Local visibility – B is a local object in a method of A
Global visibility – B is globally visible in some way
Attribute visibility
Parameter visibility
Local visibility
Factory Method
•Factory Method is a creational design pattern that provides
an interface for creating objects in a superclass, allows
subclasses to alter the type of objects that will be created.
Factory Method pattern
PROBLEM:
◦ A framework with abstract application classes and application-
specific subclasses to instantiate to realize different
implementations
SOLUTION:
◦ The Factory Method pattern encapsulates the knowledge of which
subclass to create and moves this knowledge out of the framework
Bridge pattern
The Bridge pattern is designed to separate a class's interface from its
implementation
so you can vary or replace the implementation without changing the
client code.
•Decouple an abstraction from its implementation
•Allows different implementations of an interface to be decided upon
dynamically.
•Also known as Handle/Body pattern
•Avoid a permanent binding between an abstraction and its
implementation
•Both the abstractions and their implementation should be extensible
by subclass
•Changes in the implementation of an abstraction do not impact the
clients
•Share an implementation among multi objects and this facts should
be hidden from the client
•E.g: Windows, program
Structure
Solution using Bridge
Adapter
• The adapter pattern is adapting between classes and
objects.
• Like any adapter in the real world it is used to be an
interface, a bridge between two objects.
• EX :Camera memory
Variations in Adapters
•Class Adapters
Use multiple inheritance to compose classes
•Object Adapters
Object adapters use a compositional technique to adapt
one interface to another.
Variations in Adapters
• Name : Adapter
• Problem : If similar components have different
interfaces then how to resolve incompatible interfaces.
• Solution : Using an intermediate adapter object,
convert original interface of a component to another
interface.
Object Pattern
adaptee
Use of Adapter
•Tax calculators
•Credit authorization services
•Accounting systems etc
SINGLETON
•Singleton is a class that allows only a single instance of itself
to be created and gives access to that created instance.
•It contains static variables that can accommodate unique
and private instances of itself.
Implementation of singleton
• Singleton is implemented with a ‘1‘ in the top right corner
of name compartment.
• Class X defines a static method getInstance‘ that provides
single instance of X
Class
public class Register
{
public void initialize ( )
{
… do some work…
//accessing singleton factory in a getInstance call accounting
Adapter =
ServicesFactory.getInstance().getAccountingAdapter( );
… do some work…
} //other methods…
}//end of class
UNIT IV DESIGN PATTERNS.pptx
Design Issues in implementation
public static synchronized ServiceFactory getInstance ( )
{
if (instance ==null)
{
instance = newServicesFactory ( );
}
return instance;
}
Eager initialization
public class servicesFactory
{
private static servicesFactory instance = new ServicesFactory ( );
public static servicesFactory getInstance ( )
{
Return instance;
}
// other methods…
}
Observer pattern
•To extend the solution found for changing data, add the ability for a
GUI window to refresh its sale.
•The Observer design pattern, or more accurately some
implementation of this pattern, is used to assure consistency
between different objects
Subject & Observer
Subject
◦The object which will frequently change its state and
upon which other objects depend
Observer
◦The object which depends on a subject and updates
according to its subject's state.
Observer Pattern - Example
a b c
60
y
x
5030
30
20
10
z 801010 a b c
a
b
c
a = 50%
b = 30%
c = 20%
change notification
requests, modifications
Subject
GOF(Gang of four) design patterns
1. Adapter pattern
2. Factory method
3. Singleton
4. Strategy
MAPPING DESIGN TO CODE
•The implementation Model, the UML artifacts
created during the code generation is used as input.
•The implementation artifacts consists of source code,
database definitions, JSP/XML/HTML pages
•Java
•C#
•Visual Basic
•C++
•Small talk
•Python
Defining a class with method signatures
and attributes
Creating Methods from Interaction
Diagrams
Message
public void enterItem (itemID, int qty)
ProductDescription desc = catalog.getProductDescription (itemID);
CurrentSale.makeLineItem (desc, qty);
UNIT IV DESIGN PATTERNS.pptx
Exceptions and Error Handling
•Applications development consider large – scale exception handling
strategies during design modeling.
•Indicated in the property strings of messages and operation
declarations
Exceptions and Error Handling
• Exceptions are indicated in the property strings of
messages and operation declarations.
Collection Classes in Code
• There are many one to many relationships.
• These are implemented with the collection object such as
List or Map or array
Order of Implementation
Order of Implementation

More Related Content

PPTX
Cs 1023 lec 8 design pattern (week 2)
PPTX
Creational Design Patterns.pptx
PPT
Software Design Patterns
PPT
Software Design Patterns
PPTX
Grasp principles
PPTX
Gof design patterns
PPTX
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
ODP
Design Patterns Part1
Cs 1023 lec 8 design pattern (week 2)
Creational Design Patterns.pptx
Software Design Patterns
Software Design Patterns
Grasp principles
Gof design patterns
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
Design Patterns Part1

Similar to UNIT IV DESIGN PATTERNS.pptx (20)

PPT
P Training Presentation
PPTX
Design Pattern lecture 2
PPT
Design pattern
PDF
Gof design pattern
PPT
Chapter 4_Introduction to Patterns.ppt
PPT
Chapter 4_Introduction to Patterns.ppt
PPTX
Principles of Agile Topic. Basic understanding of Agile principles.
PPTX
PPT
Introduction To Design Patterns
PPT
Design pattern in android
PPTX
Basic Concept of Object oriented Programming
PPTX
OOPSDesign PPT ( introduction to opps and design (
PPTX
Behavioral pattern By:-Priyanka Pradhan
PDF
10 Modeling Object and Classes.pdf Software
PPTX
Software Patterns
PPTX
Design pattern and their application
PDF
SE@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.ppt.pdf
PPTX
Patterns
PDF
Software Engineering with Objects (M363) Final Revision By Kuwait10
PPTX
JS Design patterns in Web technologies including oop techniques.pptx
P Training Presentation
Design Pattern lecture 2
Design pattern
Gof design pattern
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
Principles of Agile Topic. Basic understanding of Agile principles.
Introduction To Design Patterns
Design pattern in android
Basic Concept of Object oriented Programming
OOPSDesign PPT ( introduction to opps and design (
Behavioral pattern By:-Priyanka Pradhan
10 Modeling Object and Classes.pdf Software
Software Patterns
Design pattern and their application
SE@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.ppt.pdf
Patterns
Software Engineering with Objects (M363) Final Revision By Kuwait10
JS Design patterns in Web technologies including oop techniques.pptx
Ad

Recently uploaded (20)

PPTX
Welding lecture in detail for understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Internet of Things (IOT) - A guide to understanding
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Construction Project Organization Group 2.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Welding lecture in detail for understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Internet of Things (IOT) - A guide to understanding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Mechanical Engineering MATERIALS Selection
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Construction Project Organization Group 2.pptx
Digital Logic Computer Design lecture notes
Arduino robotics embedded978-1-4302-3184-4.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
UNIT 4 Total Quality Management .pptx
CH1 Production IntroductoryConcepts.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Ad

UNIT IV DESIGN PATTERNS.pptx

  • 1. UNIT IV DESIGN PATTERNS Presented By R.Krishna Prakash, Assistant Professor/CSE, Kongunadu College Of Engineering And Technology. KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY (AUTONOMOUS)
  • 3. Design Patterns • It’s typical solutions to common problems in software design. • Each pattern is like a blueprint that you can customize to solve a particular design problem in your code
  • 4. Designing objects with responsibilities • GRASP-General responsibility assignment software patterns - GRASP is a tool that helps to master the basics of OOD and understanding responsibilities - A learning aid that helps to understand for OO design with responsibilities
  • 5. • RDD -Responsibility Driven Design It’s thinking about object oriented design Doing responsibility- creating action, initializing, controlling and coordinating activities Knowing responsibilities- includes knowing about private and related data
  • 6. Applying Grasp to Object Design There are nine different GRASP patterns: (i) Creator (ii) Information expert (iii) Low coupling (iv) Controller (v) High cohesion (vi) Polymorphism (vii) Pure fabrication (viii) Indirection (ix) Protected variations
  • 7. Creator • Its one of the common activities in object oriented system is creation of object • General principle is applied for the assignment of creation responsibilities.
  • 8. If B is a creator of A objects then atleast one of the following must be true. • B contains A • B compositely aggregates A • B records A • B closely uses A
  • 10. INFORMATION EXPERT •Designing objects, interaction between objects are defined about assigning responsibilities to software classes This makes the software easier to • Maintain • Understand • Extend
  • 14. LOW COUPLING Coupling is the measure of less strongly one element is connected to the other elements. Types of coupling There are 2 types of coupling 1) Low coupling or weak coupling 2) High coupling or strong coupling
  • 15. • Low coupling An element if does not depend on too many other elements like classes, subsystems systems it is having low coupling • High coupling A class with high coupling relies on many other classes. The problems of high coupling are • Harder to understand • Harder to reuse
  • 17. Benefits for LOW Coupling •Not affected by changes in other components •Simple to understand •Convenient to reuse
  • 18. HIGH COHESION •Strongly related and focused responsibilities of an element. An element has high cohesion if it, •Difficulties of low cohesion are •Hard to comprehend •Hard to reuse •Hard to maintain
  • 20. Functional Cohesion (1) Very low cohesion • A class is solely responsible for many things in different functional areas. (2) Low cohesion • A class has sole responsibility for a complex task in one functional area. (3) High cohesion • A class has moderate responsibilities in one functional area and collaborates with others. (4) Moderate cohesion • A class has light weight. It is responsible for different areas logically related to the class concept but not to each other
  • 21. High cohesion is • Easy to maintain • Understand • Reuse Benefits of high cohesion are •Clarity •Ease of comprehension
  • 22. CONTROLLER •A controller is defined as the first object beyond the user interface (UI) layer that is responsible for the receiving or handling a system operation message.
  • 24. Design patterns Designing for visibility: • One object to have reference of another is called visibility Ex: getProductDescription message sent from a Register to a product catalog means that ProductCatalog instance is visible to register.
  • 26. Ways of visibility: from Object A to Object B Attribute visibility – B is an attribute of A Parameter visibility – B is a parameter of a method of A Local visibility – B is a local object in a method of A Global visibility – B is globally visible in some way
  • 30. Factory Method •Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, allows subclasses to alter the type of objects that will be created.
  • 31. Factory Method pattern PROBLEM: ◦ A framework with abstract application classes and application- specific subclasses to instantiate to realize different implementations SOLUTION: ◦ The Factory Method pattern encapsulates the knowledge of which subclass to create and moves this knowledge out of the framework
  • 32. Bridge pattern The Bridge pattern is designed to separate a class's interface from its implementation so you can vary or replace the implementation without changing the client code.
  • 33. •Decouple an abstraction from its implementation •Allows different implementations of an interface to be decided upon dynamically. •Also known as Handle/Body pattern
  • 34. •Avoid a permanent binding between an abstraction and its implementation •Both the abstractions and their implementation should be extensible by subclass •Changes in the implementation of an abstraction do not impact the clients •Share an implementation among multi objects and this facts should be hidden from the client •E.g: Windows, program
  • 37. Adapter • The adapter pattern is adapting between classes and objects. • Like any adapter in the real world it is used to be an interface, a bridge between two objects. • EX :Camera memory
  • 38. Variations in Adapters •Class Adapters Use multiple inheritance to compose classes •Object Adapters Object adapters use a compositional technique to adapt one interface to another.
  • 39. Variations in Adapters • Name : Adapter • Problem : If similar components have different interfaces then how to resolve incompatible interfaces. • Solution : Using an intermediate adapter object, convert original interface of a component to another interface.
  • 41. Use of Adapter •Tax calculators •Credit authorization services •Accounting systems etc
  • 42. SINGLETON •Singleton is a class that allows only a single instance of itself to be created and gives access to that created instance. •It contains static variables that can accommodate unique and private instances of itself.
  • 43. Implementation of singleton • Singleton is implemented with a ‘1‘ in the top right corner of name compartment. • Class X defines a static method getInstance‘ that provides single instance of X
  • 44. Class public class Register { public void initialize ( ) { … do some work… //accessing singleton factory in a getInstance call accounting Adapter = ServicesFactory.getInstance().getAccountingAdapter( ); … do some work… } //other methods… }//end of class
  • 46. Design Issues in implementation public static synchronized ServiceFactory getInstance ( ) { if (instance ==null) { instance = newServicesFactory ( ); } return instance; }
  • 47. Eager initialization public class servicesFactory { private static servicesFactory instance = new ServicesFactory ( ); public static servicesFactory getInstance ( ) { Return instance; } // other methods… }
  • 48. Observer pattern •To extend the solution found for changing data, add the ability for a GUI window to refresh its sale. •The Observer design pattern, or more accurately some implementation of this pattern, is used to assure consistency between different objects
  • 49. Subject & Observer Subject ◦The object which will frequently change its state and upon which other objects depend Observer ◦The object which depends on a subject and updates according to its subject's state.
  • 50. Observer Pattern - Example a b c 60 y x 5030 30 20 10 z 801010 a b c a b c a = 50% b = 30% c = 20% change notification requests, modifications Subject
  • 51. GOF(Gang of four) design patterns 1. Adapter pattern 2. Factory method 3. Singleton 4. Strategy
  • 52. MAPPING DESIGN TO CODE •The implementation Model, the UML artifacts created during the code generation is used as input. •The implementation artifacts consists of source code, database definitions, JSP/XML/HTML pages
  • 54. Defining a class with method signatures and attributes
  • 55. Creating Methods from Interaction Diagrams
  • 56. Message public void enterItem (itemID, int qty) ProductDescription desc = catalog.getProductDescription (itemID); CurrentSale.makeLineItem (desc, qty);
  • 58. Exceptions and Error Handling •Applications development consider large – scale exception handling strategies during design modeling. •Indicated in the property strings of messages and operation declarations
  • 59. Exceptions and Error Handling • Exceptions are indicated in the property strings of messages and operation declarations. Collection Classes in Code • There are many one to many relationships. • These are implemented with the collection object such as List or Map or array