SlideShare a Scribd company logo
1 of 27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Objectives
Lecture 13
Creational Design Pattern
SWE 316: Software Design and Architecture
 To learn the creational design
patterns and when to use them.
Ch 7Adapted from Software Design: From Programming
to Architecture by Eric J. Braude (Wiley 2003), with
permission.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Creational design patterns to be covered
 Creational design patterns:
 Singleton
 Factory
 Abstract factory
 Prototype
Singleton Factory Abstract Factory Prototype Summary 2/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Singleton Design Pattern
 Intent/ Design Purpose
 when a class has exactly one instance.
 Ensure that there is exactly one instance of a class S.
Be able to obtain the instance from anywhere in the
application.
 Problem
Application needs one, and only one, instance of an object.
Additionally, lazy initialization and global access are
necessary.
 Design Pattern Summary
 Make the constructor of S private; define a private
static attribute for S of type S; define a public
accessor for it.
7.3
Singleton Factory Abstract Factory Prototype Summary 3/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Singleton applicability
 Use the singleton pattern when
 There must be exactly one instance of a class, and it must
be accessible to client from a well-known access point.
 When the sole instance should be extensible by
subclassing, and clients should be able to use an
extended instance without modifying their code.
Singleton enforces the intention that only one User
object exists, safeguarding the application from
unanticipated User instance creation.
KEY CONCEPT
Design Goal: Correctness
Singleton Factory Abstract Factory Prototype Summary 4/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Singleton consequences
 Singleton has following benefits:
 Controlled access to sole instance.
 Permits a variable number of instances.
 More flexible than class operations.
Singleton Factory Abstract Factory Prototype Summary 5/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Singleton: Class Model
MyClass
getSingletonOfMyClass(): MyClass
Client
1
singletonOfMyClass
«static»
Singleton Factory Abstract Factory Prototype Summary 6/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Singleton: Sample code
7
Define a private static member
variable of type MyClass
1
Make the constructor of MyClass private2
Define a public
static method to
access the member
3
Singleton Factory Abstract Factory Prototype Summary 7/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Comments on Singleton
 This form of Singleton is simple but it creates the
Singleton object even if the object is never needed; this
is wasteful if Singleton is large.
 The idea of Singleton can be extended to the problem
of having just two instances of a class.
When a class must have exactly one instance,
make the constructor private and the instance a
private static variable with a public accessor.
KEY CONCEPT
Singleton Design Pattern
Singleton Factory Abstract Factory Prototype Summary 8/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Factory Design Pattern
 Design Purpose
Create individual objects in situations where the
constructor alone is inadequate.
 Design Pattern Summary
Use methods to return required objects.
7.2
Singleton Factory Abstract Factory Prototype Summary 9/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Factory Class Model
Factory design pattern
MyClass
createObjectOfRequiredClass(): RequiredClass
«create object»
RequiredClassClient
Singleton Factory Abstract Factory Prototype Summary 10/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Application
of Factory
design
pattern
Factory Example (Figure 7.4)
Ford
createAutomobile()
Toyota
createAutomobile()
Automobile
createAutomobile(): Automobile
Client
«create object» «create object»
We want to write code about automobiles in general: Code that
applies to any make, exercised repeatedly (thus reliably).
KEY CONCEPT
Design Goal : Reusability and Correctness
Singleton Factory Abstract Factory Prototype Summary 11/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Application of Factory design pattern
Client
sendMessage()
Customer
getMessage()
Frequent
getMessage()
Returning
getMessage()
Curious
getMessage()
Newbie
getMessage()
MailMessage
text
MailGenerationApplication
getCustomerTypeFromUser()
«setup»
Factory: Email Generation Example
Singleton Factory Abstract Factory Prototype Summary 12/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Comments on Factory
 Applications of Factory have been increasingly
common in API’s because they improve robustness by
ensuring that objects created respect necessary
constraints.
Singleton Factory Abstract Factory Prototype Summary 13/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Abstract Factory
 Design Purpose
“Provide an interface for creating families of related or
dependent objects without specifying their concrete
classes.”*
 Design Pattern
Capture family creation in a class containing a factory
method for each class in the family.
* Gamma et al
7.4
Singleton Factory Abstract Factory Prototype Summary 14/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Abstract Factory*
Abstract Factory Interface (Figure 7.17)
Style….
Client
StyleAFactory StyleBFactory
Ensemble
setAbstractFactory()
doAFunction()
AbstractFactory
getAPart1Object()
getAPart2Object()
* relationships within pattern application not shown
Singleton Factory Abstract Factory Prototype Summary 15/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Application of Abstract Factory
Interface of Abstract Factory Applied to Word
Processor
Client
SmallStyle LargeStyle
StyleDocument
setStyle()
display()
. . . . . . .
1
Singleton Factory Abstract Factory Prototype Summary 16/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
«create»
The Abstract Factory Idea (Figure 7.19)
AbstractFactory
getAPart1Object()
getAPart2Object()
StyleAFactory
getAPart1Object()
getAPart2Object()
Part1StyleA Part2StyleA
Part1 Part2
abstractFactory 1
Ensemble
setAbstractFactory()
doAFunction()
Client
Singleton Factory Abstract Factory Prototype Summary 17/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
«create»
Abstract Factory (Figure 7.20)
Style….
AbstractFactory
getAPart1Object()
getAPart2Object()
StyleAFactory StyleBFactory
Part1StyleA Part1StyleB Part2StyleA Part2StyleB
Part1 Part2
abstractFactory 1
Ensemble
doAFunction()
Client
1..n1..n
Part…
Singleton Factory Abstract Factory Prototype Summary 18/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
We want to separate the code parts that format the
document in each style. We also want to separate the
common document generation code. This facilitates
reusing parts and checking for correctness.
KEY CONCEPT
Design Goals : Correctness and Reusability
Singleton Factory Abstract Factory Prototype Summary 19/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
To design an application in which there are several
possible styles for a collection of objects, capture styles
as classes with coordinated factory methods.
KEY CONCEPT
Abstract Factory Design Pattern
Singleton Factory Abstract Factory Prototype Summary 20/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Prototype Design Pattern
 Design Purpose
 Create a set of almost identical objects whose type is
determined at runtime.
 Assume that a prototype instance is known; clone it
whenever a new instance is needed.
-- when designing for multiple
instances which are the same in
key respects, create them by
cloning a prototype.
KEY CONCEPT
Prototype Pattern
Singleton Factory Abstract Factory Prototype Summary 21/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Prototype Design Example: A Selection
Graphics courtesy COREL
Click on choice of storage:
Click on choice of chair:
Click on choice of desk:Furnit
ure
color
Furnitu
re
hardwa
re typecoloni
al
Adapted from Software Design:
From Programming to
Architecture by Eric J. Braude
(Wiley 2003), with permission.
Singleton Factory Abstract Factory Prototype Summary 22/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Prototype consequences
 It hides the concrete product classes from the client.
 It let client work with application-specific classes
without modification.
 It adds and removes products at run-time.
 It configures an application with classes dynamically.
Singleton Factory Abstract Factory Prototype Summary 23/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
The Prototype Idea
Ensemble
createEnsemble()
Client
MyPart
clone(): MyPart
MyPartStyleA
clone()
MyPartStyleB
clone()
myPartPrototype 1
// To create a MyPart instance:
MyPart p = myPartPrototype.clone();
Singleton Factory Abstract Factory Prototype Summary 24/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Prototype Class Model
Ensemble
createEnsemble()
Client
Part1StyleA
clone()
Part1StyleB
clone()
Part2StyleA
clone()
Part2StyleB
clone()
Part1
clone()
Part2
clone()
part1Prototype part2Prototype
1 1
.....
// To create a Part1 object:
Part1 p1 = part1Prototype.clone();
….
Part1StyleB returnObject = new Part1StyleB();
….
Part1StyleC
clone()
Singleton Factory Abstract Factory Prototype Summary 25/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
We want to isolate the parts pertaining to each type of
customer. We also want to isolate the common
customer code. This makes it easier to check the
design and implementation for correctness, and to
reuse the parts.
KEY CONCEPT
Design Goals : Correctness and Reusability
Singleton Factory Abstract Factory Prototype Summary 26/27
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser
Summary of Creational Patterns
 Use Creational Design Patterns when creating complex
objects
 Singleton
 for exactly one, safely
 when a class has exactly one instance
 Factory when creating individuals
 Abstract Factory when creating families
 Prototype to “mix & match”
Singleton Factory Abstract Factory Prototype Summary 27/27

More Related Content

What's hot

Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaEdureka!
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patternsLilia Sfaxi
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in androidRakesh Jha
 
Prototype design patterns
Prototype design patternsPrototype design patterns
Prototype design patternsThaichor Seng
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design PatternsAnton Keks
 
Design concept -Software Engineering
Design concept -Software EngineeringDesign concept -Software Engineering
Design concept -Software EngineeringVarsha Ajith
 
An Introduction to Software Architecture
An Introduction to Software ArchitectureAn Introduction to Software Architecture
An Introduction to Software ArchitectureRahimLotfi
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
Importance & Principles of Modeling from UML Designing
Importance & Principles of Modeling from UML DesigningImportance & Principles of Modeling from UML Designing
Importance & Principles of Modeling from UML DesigningABHISHEK KUMAR
 
Design pattern & categories
Design pattern & categoriesDesign pattern & categories
Design pattern & categoriesHimanshu
 
Design Pattern in Software Engineering
Design Pattern in Software EngineeringDesign Pattern in Software Engineering
Design Pattern in Software EngineeringManish Kumar
 

What's hot (20)

Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patterns
 
DESIGN PATTERNS: Strategy Patterns
DESIGN PATTERNS: Strategy PatternsDESIGN PATTERNS: Strategy Patterns
DESIGN PATTERNS: Strategy Patterns
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Prototype design patterns
Prototype design patternsPrototype design patterns
Prototype design patterns
 
Component based software engineering
Component based software engineeringComponent based software engineering
Component based software engineering
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
Design concept -Software Engineering
Design concept -Software EngineeringDesign concept -Software Engineering
Design concept -Software Engineering
 
An Introduction to Software Architecture
An Introduction to Software ArchitectureAn Introduction to Software Architecture
An Introduction to Software Architecture
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Importance & Principles of Modeling from UML Designing
Importance & Principles of Modeling from UML DesigningImportance & Principles of Modeling from UML Designing
Importance & Principles of Modeling from UML Designing
 
Design pattern & categories
Design pattern & categoriesDesign pattern & categories
Design pattern & categories
 
Design Pattern in Software Engineering
Design Pattern in Software EngineeringDesign Pattern in Software Engineering
Design Pattern in Software Engineering
 
Design Patterns.ppt
Design Patterns.pptDesign Patterns.ppt
Design Patterns.ppt
 
Introduction to OOAD
Introduction to OOADIntroduction to OOAD
Introduction to OOAD
 

Viewers also liked

L'acte zen du jour : ralentir votre rythme de vie
L'acte zen du jour : ralentir votre rythme de vieL'acte zen du jour : ralentir votre rythme de vie
L'acte zen du jour : ralentir votre rythme de vieOlivier Perrussel
 
Untitleddocument
UntitleddocumentUntitleddocument
UntitleddocumentRandy King
 
NRG4SD_-_Subnat_Govts_at_Forefront_of_Climate_Action-2
NRG4SD_-_Subnat_Govts_at_Forefront_of_Climate_Action-2NRG4SD_-_Subnat_Govts_at_Forefront_of_Climate_Action-2
NRG4SD_-_Subnat_Govts_at_Forefront_of_Climate_Action-2Maruxa Cardama
 
Application for post of Rig Manager 1
Application for post of Rig Manager 1Application for post of Rig Manager 1
Application for post of Rig Manager 1Grennel Pereira
 
Впровадження здровязберігаючих технологій
Впровадження здровязберігаючих технологійВпровадження здровязберігаючих технологій
Впровадження здровязберігаючих технологійЗШ № 8
 
Lithiase urinaire: épidémiologie et traitements
Lithiase urinaire: épidémiologie et traitementsLithiase urinaire: épidémiologie et traitements
Lithiase urinaire: épidémiologie et traitementsActualité de la médecine
 

Viewers also liked (10)

L'acte zen du jour : ralentir votre rythme de vie
L'acte zen du jour : ralentir votre rythme de vieL'acte zen du jour : ralentir votre rythme de vie
L'acte zen du jour : ralentir votre rythme de vie
 
Untitleddocument
UntitleddocumentUntitleddocument
Untitleddocument
 
Kinder 3ro
Kinder 3roKinder 3ro
Kinder 3ro
 
The Path to Success-2
The Path to Success-2The Path to Success-2
The Path to Success-2
 
Rangkuman pedoman pkm 2016
Rangkuman pedoman pkm 2016Rangkuman pedoman pkm 2016
Rangkuman pedoman pkm 2016
 
CV for Clifford K. Msumba IT
CV for Clifford K. Msumba ITCV for Clifford K. Msumba IT
CV for Clifford K. Msumba IT
 
NRG4SD_-_Subnat_Govts_at_Forefront_of_Climate_Action-2
NRG4SD_-_Subnat_Govts_at_Forefront_of_Climate_Action-2NRG4SD_-_Subnat_Govts_at_Forefront_of_Climate_Action-2
NRG4SD_-_Subnat_Govts_at_Forefront_of_Climate_Action-2
 
Application for post of Rig Manager 1
Application for post of Rig Manager 1Application for post of Rig Manager 1
Application for post of Rig Manager 1
 
Впровадження здровязберігаючих технологій
Впровадження здровязберігаючих технологійВпровадження здровязберігаючих технологій
Впровадження здровязберігаючих технологій
 
Lithiase urinaire: épidémiologie et traitements
Lithiase urinaire: épidémiologie et traitementsLithiase urinaire: épidémiologie et traitements
Lithiase urinaire: épidémiologie et traitements
 

Similar to Design patterns creational patterns

Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Factory Pattern
Factory PatternFactory Pattern
Factory PatternDeepti C
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptMsRAMYACSE
 
Building modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf FildebrandtBuilding modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf Fildebrandtmfrancis
 
27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examplesQuang Suma
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
Lecture 4 software process model (2)
Lecture 4   software process model (2)Lecture 4   software process model (2)
Lecture 4 software process model (2)IIUI
 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworkskim.mens
 
Design patterns intro
Design patterns introDesign patterns intro
Design patterns introJean Pаoli
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternskim.mens
 
Software Architecture Views and Viewpoints
Software Architecture Views and ViewpointsSoftware Architecture Views and Viewpoints
Software Architecture Views and ViewpointsHenry Muccini
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesSolstice Mobile Argentina
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patternssukumarraju6
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 

Similar to Design patterns creational patterns (20)

Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Factory Pattern
Factory PatternFactory Pattern
Factory Pattern
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
 
E1803023637
E1803023637E1803023637
E1803023637
 
Building modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf FildebrandtBuilding modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf Fildebrandt
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
Lecture 4 software process model (2)
Lecture 4   software process model (2)Lecture 4   software process model (2)
Lecture 4 software process model (2)
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Sda 8
Sda   8Sda   8
Sda 8
 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworks
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design patterns intro
Design patterns introDesign patterns intro
Design patterns intro
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Software Architecture Views and Viewpoints
Software Architecture Views and ViewpointsSoftware Architecture Views and Viewpoints
Software Architecture Views and Viewpoints
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best Practices
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patterns
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 

Recently uploaded

Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 

Recently uploaded (20)

Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 

Design patterns creational patterns

  • 1. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 13 Creational Design Pattern SWE 316: Software Design and Architecture  To learn the creational design patterns and when to use them. Ch 7Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
  • 2. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Creational design patterns to be covered  Creational design patterns:  Singleton  Factory  Abstract factory  Prototype Singleton Factory Abstract Factory Prototype Summary 2/27
  • 3. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Singleton Design Pattern  Intent/ Design Purpose  when a class has exactly one instance.  Ensure that there is exactly one instance of a class S. Be able to obtain the instance from anywhere in the application.  Problem Application needs one, and only one, instance of an object. Additionally, lazy initialization and global access are necessary.  Design Pattern Summary  Make the constructor of S private; define a private static attribute for S of type S; define a public accessor for it. 7.3 Singleton Factory Abstract Factory Prototype Summary 3/27
  • 4. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Singleton applicability  Use the singleton pattern when  There must be exactly one instance of a class, and it must be accessible to client from a well-known access point.  When the sole instance should be extensible by subclassing, and clients should be able to use an extended instance without modifying their code. Singleton enforces the intention that only one User object exists, safeguarding the application from unanticipated User instance creation. KEY CONCEPT Design Goal: Correctness Singleton Factory Abstract Factory Prototype Summary 4/27
  • 5. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Singleton consequences  Singleton has following benefits:  Controlled access to sole instance.  Permits a variable number of instances.  More flexible than class operations. Singleton Factory Abstract Factory Prototype Summary 5/27
  • 6. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Singleton: Class Model MyClass getSingletonOfMyClass(): MyClass Client 1 singletonOfMyClass «static» Singleton Factory Abstract Factory Prototype Summary 6/27
  • 7. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Singleton: Sample code 7 Define a private static member variable of type MyClass 1 Make the constructor of MyClass private2 Define a public static method to access the member 3 Singleton Factory Abstract Factory Prototype Summary 7/27
  • 8. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Comments on Singleton  This form of Singleton is simple but it creates the Singleton object even if the object is never needed; this is wasteful if Singleton is large.  The idea of Singleton can be extended to the problem of having just two instances of a class. When a class must have exactly one instance, make the constructor private and the instance a private static variable with a public accessor. KEY CONCEPT Singleton Design Pattern Singleton Factory Abstract Factory Prototype Summary 8/27
  • 9. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Factory Design Pattern  Design Purpose Create individual objects in situations where the constructor alone is inadequate.  Design Pattern Summary Use methods to return required objects. 7.2 Singleton Factory Abstract Factory Prototype Summary 9/27
  • 10. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Factory Class Model Factory design pattern MyClass createObjectOfRequiredClass(): RequiredClass «create object» RequiredClassClient Singleton Factory Abstract Factory Prototype Summary 10/27
  • 11. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Application of Factory design pattern Factory Example (Figure 7.4) Ford createAutomobile() Toyota createAutomobile() Automobile createAutomobile(): Automobile Client «create object» «create object» We want to write code about automobiles in general: Code that applies to any make, exercised repeatedly (thus reliably). KEY CONCEPT Design Goal : Reusability and Correctness Singleton Factory Abstract Factory Prototype Summary 11/27
  • 12. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Application of Factory design pattern Client sendMessage() Customer getMessage() Frequent getMessage() Returning getMessage() Curious getMessage() Newbie getMessage() MailMessage text MailGenerationApplication getCustomerTypeFromUser() «setup» Factory: Email Generation Example Singleton Factory Abstract Factory Prototype Summary 12/27
  • 13. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Comments on Factory  Applications of Factory have been increasingly common in API’s because they improve robustness by ensuring that objects created respect necessary constraints. Singleton Factory Abstract Factory Prototype Summary 13/27
  • 14. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Abstract Factory  Design Purpose “Provide an interface for creating families of related or dependent objects without specifying their concrete classes.”*  Design Pattern Capture family creation in a class containing a factory method for each class in the family. * Gamma et al 7.4 Singleton Factory Abstract Factory Prototype Summary 14/27
  • 15. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Abstract Factory* Abstract Factory Interface (Figure 7.17) Style…. Client StyleAFactory StyleBFactory Ensemble setAbstractFactory() doAFunction() AbstractFactory getAPart1Object() getAPart2Object() * relationships within pattern application not shown Singleton Factory Abstract Factory Prototype Summary 15/27
  • 16. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Application of Abstract Factory Interface of Abstract Factory Applied to Word Processor Client SmallStyle LargeStyle StyleDocument setStyle() display() . . . . . . . 1 Singleton Factory Abstract Factory Prototype Summary 16/27
  • 17. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser «create» The Abstract Factory Idea (Figure 7.19) AbstractFactory getAPart1Object() getAPart2Object() StyleAFactory getAPart1Object() getAPart2Object() Part1StyleA Part2StyleA Part1 Part2 abstractFactory 1 Ensemble setAbstractFactory() doAFunction() Client Singleton Factory Abstract Factory Prototype Summary 17/27
  • 18. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser «create» Abstract Factory (Figure 7.20) Style…. AbstractFactory getAPart1Object() getAPart2Object() StyleAFactory StyleBFactory Part1StyleA Part1StyleB Part2StyleA Part2StyleB Part1 Part2 abstractFactory 1 Ensemble doAFunction() Client 1..n1..n Part… Singleton Factory Abstract Factory Prototype Summary 18/27
  • 19. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser We want to separate the code parts that format the document in each style. We also want to separate the common document generation code. This facilitates reusing parts and checking for correctness. KEY CONCEPT Design Goals : Correctness and Reusability Singleton Factory Abstract Factory Prototype Summary 19/27
  • 20. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser To design an application in which there are several possible styles for a collection of objects, capture styles as classes with coordinated factory methods. KEY CONCEPT Abstract Factory Design Pattern Singleton Factory Abstract Factory Prototype Summary 20/27
  • 21. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Prototype Design Pattern  Design Purpose  Create a set of almost identical objects whose type is determined at runtime.  Assume that a prototype instance is known; clone it whenever a new instance is needed. -- when designing for multiple instances which are the same in key respects, create them by cloning a prototype. KEY CONCEPT Prototype Pattern Singleton Factory Abstract Factory Prototype Summary 21/27
  • 22. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Prototype Design Example: A Selection Graphics courtesy COREL Click on choice of storage: Click on choice of chair: Click on choice of desk:Furnit ure color Furnitu re hardwa re typecoloni al Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission. Singleton Factory Abstract Factory Prototype Summary 22/27
  • 23. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Prototype consequences  It hides the concrete product classes from the client.  It let client work with application-specific classes without modification.  It adds and removes products at run-time.  It configures an application with classes dynamically. Singleton Factory Abstract Factory Prototype Summary 23/27
  • 24. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser The Prototype Idea Ensemble createEnsemble() Client MyPart clone(): MyPart MyPartStyleA clone() MyPartStyleB clone() myPartPrototype 1 // To create a MyPart instance: MyPart p = myPartPrototype.clone(); Singleton Factory Abstract Factory Prototype Summary 24/27
  • 25. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Prototype Class Model Ensemble createEnsemble() Client Part1StyleA clone() Part1StyleB clone() Part2StyleA clone() Part2StyleB clone() Part1 clone() Part2 clone() part1Prototype part2Prototype 1 1 ..... // To create a Part1 object: Part1 p1 = part1Prototype.clone(); …. Part1StyleB returnObject = new Part1StyleB(); …. Part1StyleC clone() Singleton Factory Abstract Factory Prototype Summary 25/27
  • 26. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser We want to isolate the parts pertaining to each type of customer. We also want to isolate the common customer code. This makes it easier to check the design and implementation for correctness, and to reuse the parts. KEY CONCEPT Design Goals : Correctness and Reusability Singleton Factory Abstract Factory Prototype Summary 26/27
  • 27. SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Summary of Creational Patterns  Use Creational Design Patterns when creating complex objects  Singleton  for exactly one, safely  when a class has exactly one instance  Factory when creating individuals  Abstract Factory when creating families  Prototype to “mix & match” Singleton Factory Abstract Factory Prototype Summary 27/27

Editor's Notes

  1. In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.
  2. A class of which only a single instance can exist