Nov 200391.3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (section 23.3 has a Simple.

Slides:



Advertisements
Similar presentations
Chapter 5: The Singleton Pattern
Advertisements

More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Jan Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Sequence Diagram Objects are represented horizontally across the top of the diagram Each object has a lifeline some exist before and/or after some are.
Oct Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
 Consists of Creational patterns  Each generator pattern has a Client, Product, and Generator.  The Generator needs at least one operation that creates.
Fall 2009ACS-3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (Simple Factory) Prototype.
March R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (in Larman) Prototype Singleton.
Design Patterns CS is not simply about programming
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
March R McFadyen1 Façade. March R McFadyen2 Facade P Main Entry: fa·cade Variant(s): also fa·çade / f&-'säd/ Function: noun.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Fall 2009ACS-3913 R. McFadyen1 Polymorphism Indirection Pure Fabrication Protected Variations (Law of Demeter) More GRASP Patterns.
March R McFadyen1 GoF (Gang of Four): Gamma, Johnson, Helm & Vlissides Book: Design Patterns: Elements of Reusable Object-Oriented Software.
Spring 2010ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Fall 2009ACS-3913 R McFadyen1 Singleton Problem: Exactly one instance of a certain object is required (this object is called a singleton). We must ensure.
Winter 2007ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
CSSE 374: Introduction to Gang of Four Design Patterns
ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Answers A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns 1.
Advanced Programming Rabie A. Ramadan 7.
Factory, Singleton & Strategy All References and Material From: Applying UML and Patterns, 3 rd ed, chpt 26 & 13 BTS530: Major Project Planning and Design.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Creational Patterns
1 More OO Design Patterns CSC 335: Object-Oriented Programming and Design.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
Singleton Pattern Presented By:- Navaneet Kumar ise
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
Object-Oriented Analysis and Design Week 12, 2009.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
Elaboration: Iteration 2. Elaboration: Iteration 2 Basics Iteration 1 ends with : All the software has been tested: The idea in the UP is to do early,
Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Design Patterns – Chocolate Factory (from Head First Design Patterns)
Week 2, Day 1: The Factory Method Pattern
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
More Interfaces, Dynamic Binding, and Polymorphism
Design Patterns (GoF) contains the creational patterns:
Design Patterns in Operating Systems
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
GoF Design Patterns (Ch. 26)
Object Oriented Design Patterns - Creational Patterns
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
GoF Design Patterns (Ch. 26)
CS 350 – Software Design Singleton – Chapter 21
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Design pattern Lecture 6.
GoF Patterns Ch. 26.
Presentation transcript:

Nov R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (section 23.3 has a Simple Factory) Prototype Singleton (23.4) These are creational patterns for the instantiation process Help to make a system independent of how its objects are created They hide how instances of classes are created GoF Patterns (Aside)

Nov R McFadyen2 Simple Factory (23.3) Problem: who should be responsible for creating objects when there are special considerations such as complex creational logic, … Solution: create a Pure Fabrication object called a Factory that handles the creation. (The factory creates objects.) E.g. Which adapters should exist when NextGenPOS is running? The text presents a class that determines which adapters will be instantiated. Simple Factory Pattern

Nov R McFadyen3 Textbook example The NextGen POS system supports several kinds of 3 rd party services. For example: tax calculators such as TaxMaster and Good As Gold, account packages such as SAP and Great Northern. The support is provided through “adapters”. The text is concerned with determining the class that should create the required adapters. Choosing a class in the domain model will lower the cohesion of that class. Instead we apply pure fabrication, and using the Simple Factory Pattern, we have a Factory class that has the responsibility to create such adapter objects. Simple Factory Pattern

Nov R McFadyen4 Textbook example ServicesFactory is a class that is responsible for creating the various adapters required in NextGenPOS. It is a factory. Simple Factory Pattern ServicesFactory accountingAdapter:… inventoryAdapter:… taxCalculatorAdapter:… getAccountingAdapter():… getInventoryAdapter():… getTaxCalculatorAdapter():…

Nov R McFadyen5 Textbook example Suppose an external source contains the names of the adapters that are to be used. This source is available at runtime. ServicesFactory accesses this source and instantiates the correct adapter objects. Different adapters will be instantiated for different NextGenPOS systems. Simple Factory Pattern ServicesFactory accountingAdapter:… inventoryAdapter:… taxCalculatorAdapter:… getAccountingAdapter():… getInventoryAdapter():… getTaxCalculatorAdapter():…

Nov R McFadyen6 Singleton (23.4) Problem: Exactly one instance of a certain object is required (this object is called a singleton). We must ensure a class has only one instance. Solution: use a static method of the class to return the singleton Factories and Facades are usually singletons. Textbook problem: how do we control the instantiation of the ServicesFactory? Singleton Pattern

Nov R McFadyen7 Singleton (23.4) In Java, you would have code such as: Public static synchronized ServicesFactory getInstance() { If (instance == null) Instance := new ServicesFactory() Return instance } Singleton Pattern The point of the above is that only one instance is ever created. If one already exists, then the create is bypassed and the reference to the existing object is returned.

Nov R McFadyen8 Singleton (23.4) In Java, you would have code such as: Public static synchronized ServicesFactory getInstance() { If (instance == null) Instance := new ServicesFactory() Return instance } Singleton Pattern The “synchronized” keyword ensures that only one “thread” runs this code at a time. The text refers to a “critical section”.

Nov R McFadyen9 Singleton Pattern Suppose an instance of the ServicesFactory is created and, later on, a message, getTaxCalculatorAdapter(), is passed to this instance. (Note: on page 350 the text makes reference to the situation illustrated below as “uninteresting”) :Register :ServicesFactory getInstance() ServicesFactory create() getTaxCalculatorAdapter()

Nov R McFadyen10 Singleton Pattern Figure 23.6 :Register :AccountingAdapter getAccountingAdapter() > :ServicesFactory create() post() By applying the > stereotype to this object, they are implying that the getInstance method was used to instantiate it.

Nov R McFadyen11 Singleton Pattern The text makes reference to Lazy Instantiation – The ServicesFactory object was created when it was needed, and not before :Register :AccountingAdapter getAccountingAdapter() > :ServicesFactory create() post()

Nov R McFadyen12 Patterns Quote from text, p 352: “To handle the problem of varying interfaces for external services, let’s use Adapters generated from a Singleton Factory” :Register :AccountingAdapter getAccountingAdapter() > :ServicesFactory create()...