T O K ILL A S INGLETON F ACTORY M ETHOD P ATTERN Josh Mason 6/18/09.

Slides:



Advertisements
Similar presentations
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Advertisements

CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
ITEC200 – Week03 Inheritance and Class Hierarchies.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
 Consists of Creational patterns  Each generator pattern has a Client, Product, and Generator.  The Generator needs at least one operation that creates.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Design Patterns I 1. Creational Pattern Singleton: intent and structure Ensure a class has one instance, and provide a global point of access to it 2.
DESIGN PATTERNS Redesigning Applications And
Creational Patterns: The Abstract Factory CSE 335 Spring 2008 E. Kraemer.
OOP Languages: Java vs C++
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
Design Patterns.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
02 - Creational Design Patterns Moshe Fresko Bar-Ilan University תשס"ח 2008.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Programming Languages and Paradigms Object-Oriented Programming.
12/6/20041 The Factory Method Pattern Presenters 王世賀 F 陳祐毓 F 張峻銘 F 吳佩達 F 林俊成 F 鄭榮智 F 許書豪 F
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
Mohammed Al-Dhelaan CSci 253 Object Oriented Design Instructor: Brad Taylor 06/02/2009 Factory Method Pattern.
Programming in Java CSCI-2220 Object Oriented Programming.
Abstract Classes. Review PA – 3 Design Considerations /Web/CS239/programs/pa3/draft.php ?harrisnlCS239
Factory Method Chris Colasuonno Also known as “Virtual Constructor”
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
The Factory Method Design Pattern Motivation: Class / Type separation – Abstract class serves as type definition and concrete class provides implementation.
CDP-1 9. Creational Pattern. CDP-2 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are –created –composed.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Prototype pattern Participants Prototype (Graphic) – declared an interface for cloning itself ConcretePrototype (EditBox, Slider) – implements an operation.
CS 590L – Distributed Component Architecture 02/20/2003Uttara Paingankar1 Design Patterns: Factory Method The factory method defines an interface for creating.
FACTORY METHOD. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns I.
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
The Factory Pattern Sanjay Yadav (ISE ).
Advanced Object-oriented Design Patterns Creational Design Patterns.
CSC 480 Software Engineering Design With Patterns.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Overview of C++ Polymorphism
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Abstract Factory Pattern Jiaxin Wang CSPP Winter 2010.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
SOFTWARE DESIGN Design Patterns 1 6/14/2016Computer Science Department, TUC-N.
Factory Method. Intent/Purpose Factory Method is used to deal with a problem of creating objects without specifying the EXACT class of object that we.
Design Patterns: MORE Examples
Factory Method Pattern
How to be a Good Developer
Low Budget Productions, LLC
Factory Patterns 1.
Software Design and Architecture
Object-Oriented Programming
Factory Method Pattern
Object Oriented Design Patterns - Creational Patterns
CSE 432 Presentation GoF: Factory Method PH: “To Kill a Singleton”
Java Inheritance.
Fundaments of Game Design
Overview of C++ Polymorphism
Creational Patterns.
Presentation transcript:

T O K ILL A S INGLETON F ACTORY M ETHOD P ATTERN Josh Mason 6/18/09

T O K ILL A S INGLETON Will try and answer these important questions Who deletes a singleton? How do you go about deleting a singleton?

O RIGINAL D ESIGN Recall Single Instance of a class Class controls its own creation Not addressed Destructors Deletion/Cleanup Key ideas to keep in mind Destruction order Dangling references Singletons typically long lived

P OSSIBLE S OLUTIONS Explicit destruction *Singleton destroyer *Static function variable

S INGLETON D ESTROYER Static object in Singleton class Manages singleton instance Automagically cleans up Singleton class on program exit Consequences Order of static object destruction undefined (in C++) Requires use of friend keyword to access protected instance Only cleaned up on process termination

S TATIC F UNCTION V ARIABLE Declare instance variable in Instance() as static Return reference to instance variable Automagically cleans up Singleton class on program exit Consequences Don’t need SingletonDestroyer Uses object notation instead of dereference notation (. vs -> in C++) Still doesn’t solve order singletons with mutual dependency Only cleaned up on process termination

F ACTORY M ETHOD P ATTERN Creational Pattern Defines interface for creation of objects, but lets subclasses decide which class to instantiate Defers instantiation to subclasses Commonly used to “refer to any method whose main purpose is creation of objects”

A PPLICABILITY Use the Factory Method Pattern when A class can’t anticipate the class of objects it must create A class wants its subclasses to specify the object it creates Classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate.

C LASS D IAGRAM

P ARTICIPANTS Product Defines product interface Concrete Product Implements Product interface Creator Declares FactoryMethod() May call FactoryMethod() to create object Concrete Creator Overrides FactoryMethod() to return an instance of Concrete Product

C ONSEQUENCES Provides hooks for subclasses Eliminates the need to bind application-specific classes into code. Enables the subclasses to provide an extended version of an object Connects parallel class hierarchies

E XAMPLE

C ONSIDERATIONS ON I MPLEMENTATION Two major varieties Creator is abstract and provides no default implementation Creator is concrete and provides default implementation Parameterized factory methods Use of templates to avoid subclassing Name factory method appropriately

R ELATED P ATTERNS Abstract Factory Template Method Defers some steps to children. Specifically creation of object Prototype Doesn’t require subclassing Creator. Often require Initialize operation on Product class which Factory Method doesn't require.