SlideShare a Scribd company logo
Design Patterns
Last Time
• Introduced design patterns
• Abstraction-Occurrence
• General Hierarchy
• Player-Role
This Time
• Singleton pattern
• Observer pattern
• Delegation pattern
• Adapter pattern
• Façade pattern
• Immutable pattern
• Read-Only Interface pattern
• Factory pattern
Singleton
• Context
– Common to want only one instance of a class
– Referred to as a singleton
– E.g. a Company or University class
• Problem
– How to ensure only one instance
• Forces
– Public constructor will not guarantee only one
instance
– Constructor must be accessible to all classes that need
it, though.
Singleton
• Solution
– Use a private class variable for one (the) instance of the class
– Use a public static class method runs the constructor only on its first
call, and make the constructor private
Observer
• Context
– Two way associations make code for pairs of classes
inseparable
– Need both classes for reuse
• Problem
– How to reduce interconnection between classes
– How to ensure communication with other objects
without knowing what class they belong to
• Forces
– Maximize flexibility
Observer
• Solution
– Create abstract class called <<Observable>>
– Includes mechanism to add and remove observers
– Method to send an update message to each
<<Observer>>
– Allow any application class to be <<Observable>>
• <<Observer>> is an interface with an abstract
update method
Observer
Observer
• Examples
– A Forecaster object would perform many calculations
– WeatherViewer is needed to obtain values from this
object
– Java contains an Observer interface and an
Observable class
• Anti-patterns
– Connecting an observer directly to something that is
observable
– Making observers subclasses of what is observable
Delegation
• Context
– Creating a method for a class
– Another class already has that operation
– Inheritance should not be used because the “is-a” rule
does not apply
• Problem
– Effectively make use of a method existing in another class
• Forces
– Development costs should be minimized by reusing
methods from other classes
– Ensure work is completed by an appropriate class
Delegation
• Solution
– Create a <<Delegator>> class that calls a method in an
associated <<Delegate>> class
– Typically an association already exists between the
<<Delegator>> and the <<Delegate>>
– Sometimes such an association is created if it reduces
system complexity
– Delegation could be viewed as a form of selective
inheritance
– Some languages like C# support delegates using a
keyword
Delegation
Delegation
Delegation
• Anti-patterns
– Common to inherit method to be reused instead
of delegating it
– Should avoid duplicating code unless necessary
– Should avoid directly accessing code within the
delegate class that is outside of the delegated
method
Adapter
• Context
– Incorporate an existing class into an inheritance
hierarchy
– Methods may have different names and class may be
part of its own inheritance hierarchy
• Problem
– How to use polymorphism when reusing a class with
the same functionality but a different signature
• Forces
– Assume multiple inheritance does not exist
Adapter
• Solution
– Create an <<Adapter>> class that connects via association to an
<<Adaptee>>
– The methods of <<Adapter>> delegate to those of the
<<Adaptee>>
– Sometimes called a wrapper class
Adapter
Façade
• Context
– Need to manipulate many different classes in many
packages
• Problem
– Simplify the programmer’s view of these packages
• Forces
– Often hard to understand and use an entire subsystem
– Modifications made to the package would necessitate
a complete review of its subsystems
Façade
• Solution
– Use a <<Façade>> class to simplify use of the package(s)
– Create a simplified set of public methods to interact with the package(s)
– Changes should only need to be made to the <<Façade>> rather than the
package(s)
Immutable
• Context
– Immutable object has a state that never changes after creation – e.g. a Java
String
– Content can be trusted to not change unexpectedly
• Problem
– How to create a class with immutable instances
• Forces
– Immutability must be enforced
– Don’t allow loopholes
• Solution
– Only allow instance variables to be modified within the constructor
– Instance methods should have no side effects
– Instead of using side effects to modify instance variables, instance methods
should create a new instance of the class and return a new object with new
values containing the results of the side effect
Read-Only Interface
• Context
– Create a privileged class that may modify attributes of objects that are
otherwise immutable
• Problem
– How to create a situation where some classes see another as read-
only
• Forces
– Java allows access control by public, private, and protected keywords,
but public access still allows read and write access
• Solution
– Create a <<Mutable>> class that you may pass instances of to methods
that are allowed to make changes
– Allow associations to unprivileged classes only through a
<<ReadOnlyInterface>>
Read-Only Interface
Read-Only Interface
Proxy
• Context
– Sometimes it is time consuming or complicated to create
instances of a class that has lots of data (a heavyweight class)
– Could cost CPU time, memory usage, etc.
• Problem
– Reduce the need to create instances of such classes
• Forces
– Want availability of such heavyweight objects without the cost
– Persistence of these objects from run to run is key
• Solution
– Create a simpler version of the <<HeavyWeight>> class called a
<<Proxy>>
– The <<Proxy>> has the same interface as the <<HeavyWeight>>
Proxy
Proxy
Factory
• Context
– Have reusable framework that creates objects but created objects depend upon the
application
• Problem
– Allow programmer to add an <<ApplSpecificClass>> into the framework
– Allow framework to instantiate this class without modifying the framework
• Forces
– Want framework benefits and flexibility of having the framework to create and work with
application-specific classes that the framework does not yet know about
• Solution
– Framework delegates creation of instances of <<ApplSpecificClass>> to a specialized class
<<ApplSpecificFactory>>
– <<ApplSpecificFactory>> implements a generic <<Factory>> interface that is predefined within
the framework
– <<Factory>> contains an abstract method called createInstance that is implemented by
<<ApplSpecificFactory>>
– A <<CreationRequester>> declares a method to create a <<Factory>> of <<GenericClass>>
which can be carried out with an <<ApplSpecificFactory>> and an <<ApplSpecificClass>>
Factory
Factory

More Related Content

What's hot

Full-Stack Development
Full-Stack DevelopmentFull-Stack Development
Full-Stack Development
Dhilipsiva DS
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Akshay Mathur
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
Outware Mobile
 
Git
GitGit
Introduction to github slideshare
Introduction to github slideshareIntroduction to github slideshare
Introduction to github slideshare
Rakesh Sukumar
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
Max Claus Nunes
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
Shahzad
 
A brief introduction to version control systems
A brief introduction to version control systemsA brief introduction to version control systems
A brief introduction to version control systems
Tim Staley
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask Presentation
Parag Mujumdar
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Design patterns in PHP
Design patterns in PHPDesign patterns in PHP
Design patterns in PHP
Jason Straughan
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
Alex Movila
 
Spring Boot
Spring BootSpring Boot
Spring Boot
HongSeong Jeon
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
Livares Technologies Pvt Ltd
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
kim.mens
 
Nuxtjs cheat-sheet
Nuxtjs cheat-sheetNuxtjs cheat-sheet
Nuxtjs cheat-sheet
ValeriaCastillo71
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
Asma CHERIF
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Joseph de Castelnau
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
Dilum Navanjana
 

What's hot (20)

Full-Stack Development
Full-Stack DevelopmentFull-Stack Development
Full-Stack Development
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
Git
GitGit
Git
 
Introduction to github slideshare
Introduction to github slideshareIntroduction to github slideshare
Introduction to github slideshare
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
A brief introduction to version control systems
A brief introduction to version control systemsA brief introduction to version control systems
A brief introduction to version control systems
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask Presentation
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Design patterns in PHP
Design patterns in PHPDesign patterns in PHP
Design patterns in PHP
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Nuxtjs cheat-sheet
Nuxtjs cheat-sheetNuxtjs cheat-sheet
Nuxtjs cheat-sheet
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 

Viewers also liked

2015 bioinformatics wim_vancriekinge
2015 bioinformatics wim_vancriekinge2015 bioinformatics wim_vancriekinge
2015 bioinformatics wim_vancriekinge
Prof. Wim Van Criekinge
 
International Primary Care Conference March 2016 Walter Kmet
International Primary Care Conference March 2016 Walter KmetInternational Primary Care Conference March 2016 Walter Kmet
International Primary Care Conference March 2016 Walter Kmet
Walter Kmet
 
CHF AHHA Workshop 25th August 16
CHF AHHA Workshop 25th August 16CHF AHHA Workshop 25th August 16
CHF AHHA Workshop 25th August 16
Walter Kmet
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
Tony Nguyen
 
Inspirational Quotes about Life
Inspirational Quotes about LifeInspirational Quotes about Life
Inspirational Quotes about Life
lance5rosa97
 
Acuerdo de MORENA con el magisterio de Quintana Roo
Acuerdo de MORENA con el magisterio de Quintana RooAcuerdo de MORENA con el magisterio de Quintana Roo
Acuerdo de MORENA con el magisterio de Quintana Roo
AMLO-MORENA
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Hassan Ahmed
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
Tony Nguyen
 
Ψηφιακή Χαρτογραφία & Γεωπληροφορική - 3ο μέρος
Ψηφιακή Χαρτογραφία & Γεωπληροφορική - 3ο μέροςΨηφιακή Χαρτογραφία & Γεωπληροφορική - 3ο μέρος
Ψηφιακή Χαρτογραφία & Γεωπληροφορική - 3ο μέρος
John Tzortzakis
 
κοινωνική και πολιτική αγωγή 1
κοινωνική και πολιτική  αγωγή 1κοινωνική και πολιτική  αγωγή 1
κοινωνική και πολιτική αγωγή 1
Eleni Vasilaki
 
Acuerdo para mejorar la educación en Baja California
Acuerdo para mejorar la educación en Baja CaliforniaAcuerdo para mejorar la educación en Baja California
Acuerdo para mejorar la educación en Baja California
AMLO-MORENA
 
Acuerdo de MORENA con el magisterio de la Ciudad de México
Acuerdo de MORENA con el magisterio de la Ciudad de MéxicoAcuerdo de MORENA con el magisterio de la Ciudad de México
Acuerdo de MORENA con el magisterio de la Ciudad de México
AMLO-MORENA
 
Threads
ThreadsThreads
Threads
Shivam Singh
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
Babeetha Muruganantham
 

Viewers also liked (17)

Api crash
Api crashApi crash
Api crash
 
2015 bioinformatics wim_vancriekinge
2015 bioinformatics wim_vancriekinge2015 bioinformatics wim_vancriekinge
2015 bioinformatics wim_vancriekinge
 
International Primary Care Conference March 2016 Walter Kmet
International Primary Care Conference March 2016 Walter KmetInternational Primary Care Conference March 2016 Walter Kmet
International Primary Care Conference March 2016 Walter Kmet
 
CHF AHHA Workshop 25th August 16
CHF AHHA Workshop 25th August 16CHF AHHA Workshop 25th August 16
CHF AHHA Workshop 25th August 16
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Inspirational Quotes about Life
Inspirational Quotes about LifeInspirational Quotes about Life
Inspirational Quotes about Life
 
Lunga CV 2016
Lunga CV 2016Lunga CV 2016
Lunga CV 2016
 
Acuerdo de MORENA con el magisterio de Quintana Roo
Acuerdo de MORENA con el magisterio de Quintana RooAcuerdo de MORENA con el magisterio de Quintana Roo
Acuerdo de MORENA con el magisterio de Quintana Roo
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
Ψηφιακή Χαρτογραφία & Γεωπληροφορική - 3ο μέρος
Ψηφιακή Χαρτογραφία & Γεωπληροφορική - 3ο μέροςΨηφιακή Χαρτογραφία & Γεωπληροφορική - 3ο μέρος
Ψηφιακή Χαρτογραφία & Γεωπληροφορική - 3ο μέρος
 
Abstract class
Abstract classAbstract class
Abstract class
 
κοινωνική και πολιτική αγωγή 1
κοινωνική και πολιτική  αγωγή 1κοινωνική και πολιτική  αγωγή 1
κοινωνική και πολιτική αγωγή 1
 
Acuerdo para mejorar la educación en Baja California
Acuerdo para mejorar la educación en Baja CaliforniaAcuerdo para mejorar la educación en Baja California
Acuerdo para mejorar la educación en Baja California
 
Acuerdo de MORENA con el magisterio de la Ciudad de México
Acuerdo de MORENA con el magisterio de la Ciudad de MéxicoAcuerdo de MORENA con el magisterio de la Ciudad de México
Acuerdo de MORENA con el magisterio de la Ciudad de México
 
Threads
ThreadsThreads
Threads
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 

Similar to Design patterns

Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 
Introduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptIntroduction to Design Patterns in Javascript
Introduction to Design Patterns in Javascript
Santhosh Kumar Srinivasan
 
Design patterns Structural
Design patterns StructuralDesign patterns Structural
Design patterns Structural
UMAR ALI
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
Polymorphism
PolymorphismPolymorphism
PolymorphismKumar
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingAllan Mangune
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
RushikeshChikane1
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
RushikeshChikane2
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Amr Abd El Latief
 
Design patterns
Design patternsDesign patterns
Design patterns
Ahmed Kamel Taha
 
Object oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented conceptsObject oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented concepts
Vaibhav Khanna
 
Java inheritance concept, interface, objects, extends
Java inheritance concept, interface, objects, extendsJava inheritance concept, interface, objects, extends
Java inheritance concept, interface, objects, extends
HelariaXavier
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
Sumit Srivastava
 
Design patterns
Design patternsDesign patterns
Design patternsAlok Guha
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
Kazuhiro Sera
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Sachintha Gunasena
 

Similar to Design patterns (20)

Design Patterns - GOF
Design Patterns - GOFDesign Patterns - GOF
Design Patterns - GOF
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Introduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptIntroduction to Design Patterns in Javascript
Introduction to Design Patterns in Javascript
 
Design patterns Structural
Design patterns StructuralDesign patterns Structural
Design patterns Structural
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & Programming
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Ch06.ppt
Ch06.pptCh06.ppt
Ch06.ppt
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Object oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented conceptsObject oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented concepts
 
Java inheritance concept, interface, objects, extends
Java inheritance concept, interface, objects, extendsJava inheritance concept, interface, objects, extends
Java inheritance concept, interface, objects, extends
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1
 

More from Luis Goldster

Ruby on rails evaluation
Ruby on rails evaluationRuby on rails evaluation
Ruby on rails evaluation
Luis Goldster
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
Luis Goldster
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworks
Luis Goldster
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
Luis Goldster
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
Luis Goldster
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
Luis Goldster
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
Luis Goldster
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
Luis Goldster
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
Luis Goldster
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
Luis Goldster
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Luis Goldster
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
Luis Goldster
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
Luis Goldster
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
Luis Goldster
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Luis Goldster
 

More from Luis Goldster (20)

Ruby on rails evaluation
Ruby on rails evaluationRuby on rails evaluation
Ruby on rails evaluation
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworks
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
 
Cache recap
Cache recapCache recap
Cache recap
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Api crash
Api crashApi crash
Api crash
 
Object model
Object modelObject model
Object model
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Abstract class
Abstract classAbstract class
Abstract class
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 

Recently uploaded

20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 

Recently uploaded (20)

20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 

Design patterns

  • 2. Last Time • Introduced design patterns • Abstraction-Occurrence • General Hierarchy • Player-Role
  • 3. This Time • Singleton pattern • Observer pattern • Delegation pattern • Adapter pattern • Façade pattern • Immutable pattern • Read-Only Interface pattern • Factory pattern
  • 4. Singleton • Context – Common to want only one instance of a class – Referred to as a singleton – E.g. a Company or University class • Problem – How to ensure only one instance • Forces – Public constructor will not guarantee only one instance – Constructor must be accessible to all classes that need it, though.
  • 5. Singleton • Solution – Use a private class variable for one (the) instance of the class – Use a public static class method runs the constructor only on its first call, and make the constructor private
  • 6. Observer • Context – Two way associations make code for pairs of classes inseparable – Need both classes for reuse • Problem – How to reduce interconnection between classes – How to ensure communication with other objects without knowing what class they belong to • Forces – Maximize flexibility
  • 7. Observer • Solution – Create abstract class called <<Observable>> – Includes mechanism to add and remove observers – Method to send an update message to each <<Observer>> – Allow any application class to be <<Observable>> • <<Observer>> is an interface with an abstract update method
  • 9. Observer • Examples – A Forecaster object would perform many calculations – WeatherViewer is needed to obtain values from this object – Java contains an Observer interface and an Observable class • Anti-patterns – Connecting an observer directly to something that is observable – Making observers subclasses of what is observable
  • 10. Delegation • Context – Creating a method for a class – Another class already has that operation – Inheritance should not be used because the “is-a” rule does not apply • Problem – Effectively make use of a method existing in another class • Forces – Development costs should be minimized by reusing methods from other classes – Ensure work is completed by an appropriate class
  • 11. Delegation • Solution – Create a <<Delegator>> class that calls a method in an associated <<Delegate>> class – Typically an association already exists between the <<Delegator>> and the <<Delegate>> – Sometimes such an association is created if it reduces system complexity – Delegation could be viewed as a form of selective inheritance – Some languages like C# support delegates using a keyword
  • 14. Delegation • Anti-patterns – Common to inherit method to be reused instead of delegating it – Should avoid duplicating code unless necessary – Should avoid directly accessing code within the delegate class that is outside of the delegated method
  • 15. Adapter • Context – Incorporate an existing class into an inheritance hierarchy – Methods may have different names and class may be part of its own inheritance hierarchy • Problem – How to use polymorphism when reusing a class with the same functionality but a different signature • Forces – Assume multiple inheritance does not exist
  • 16. Adapter • Solution – Create an <<Adapter>> class that connects via association to an <<Adaptee>> – The methods of <<Adapter>> delegate to those of the <<Adaptee>> – Sometimes called a wrapper class
  • 18. Façade • Context – Need to manipulate many different classes in many packages • Problem – Simplify the programmer’s view of these packages • Forces – Often hard to understand and use an entire subsystem – Modifications made to the package would necessitate a complete review of its subsystems
  • 19. Façade • Solution – Use a <<Façade>> class to simplify use of the package(s) – Create a simplified set of public methods to interact with the package(s) – Changes should only need to be made to the <<Façade>> rather than the package(s)
  • 20. Immutable • Context – Immutable object has a state that never changes after creation – e.g. a Java String – Content can be trusted to not change unexpectedly • Problem – How to create a class with immutable instances • Forces – Immutability must be enforced – Don’t allow loopholes • Solution – Only allow instance variables to be modified within the constructor – Instance methods should have no side effects – Instead of using side effects to modify instance variables, instance methods should create a new instance of the class and return a new object with new values containing the results of the side effect
  • 21. Read-Only Interface • Context – Create a privileged class that may modify attributes of objects that are otherwise immutable • Problem – How to create a situation where some classes see another as read- only • Forces – Java allows access control by public, private, and protected keywords, but public access still allows read and write access • Solution – Create a <<Mutable>> class that you may pass instances of to methods that are allowed to make changes – Allow associations to unprivileged classes only through a <<ReadOnlyInterface>>
  • 24. Proxy • Context – Sometimes it is time consuming or complicated to create instances of a class that has lots of data (a heavyweight class) – Could cost CPU time, memory usage, etc. • Problem – Reduce the need to create instances of such classes • Forces – Want availability of such heavyweight objects without the cost – Persistence of these objects from run to run is key • Solution – Create a simpler version of the <<HeavyWeight>> class called a <<Proxy>> – The <<Proxy>> has the same interface as the <<HeavyWeight>>
  • 25. Proxy
  • 26. Proxy
  • 27. Factory • Context – Have reusable framework that creates objects but created objects depend upon the application • Problem – Allow programmer to add an <<ApplSpecificClass>> into the framework – Allow framework to instantiate this class without modifying the framework • Forces – Want framework benefits and flexibility of having the framework to create and work with application-specific classes that the framework does not yet know about • Solution – Framework delegates creation of instances of <<ApplSpecificClass>> to a specialized class <<ApplSpecificFactory>> – <<ApplSpecificFactory>> implements a generic <<Factory>> interface that is predefined within the framework – <<Factory>> contains an abstract method called createInstance that is implemented by <<ApplSpecificFactory>> – A <<CreationRequester>> declares a method to create a <<Factory>> of <<GenericClass>> which can be carried out with an <<ApplSpecificFactory>> and an <<ApplSpecificClass>>