Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.

Similar documents
Factory Method Pattern Creational. » Define an interface for creating an object but lets subclasses decide the specific class to instantiate

Object-Oriented Oriented Programming Factory Method Pattern Abstract Factory Pattern. CSIE Department, NTUT Woei-Kae Chen

Brief Note on Design Pattern

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Tecniche di Progettazione: Design Patterns

Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z)

Introduction to Software Engineering: Object Design I Reuse & Patterns

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Tecniche di Progettazione: Design Patterns

Software Design COSC 4353/6353 D R. R A J S I N G H

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

SDC Design patterns GoF

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts

The Strategy Pattern Design Principle: Design Principle: Design Principle:

DESIGN PATTERNS FOR MERE MORTALS

Design Pattern- Creational pattern 2015

What is Design Patterns?

Prototype Description. Interpreter. interpreter Calculator Design Rationales. Prototype Participants. Interpreter with Factory Method.

Appendix-A. A.1 Catalogues of Design Patterns. Below is the definition for each design pattern using the FINDER notation, followed

Lecture 13: Design Patterns

Dr. Xiaolin Hu. Review of last class

Factory Method Pattern Tutorial Written Date : September 28, 2009

Lecture 21: Design Patterns III

Pattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Object-oriented Software Design Patterns

Creational Patterns. Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU)

CSE870: Advanced Software Engineering (Cheng) 1

OODP Session 5a. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Object-Oriented Design

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

Reuse at Design Level: Design Patterns

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Object-Oriented Oriented Programming

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Design Patterns. GoF design patterns catalog

C++ Inheritance and Encapsulation

SOLID DESIGN PATTERNS FOR MERE MORTALS

Software Design COSC 4353/6353 D R. R A J S I N G H

Design patterns. Jef De Smedt Beta VZW

CS 2720 Practical Software Development University of Lethbridge. Design Patterns

Design patterns. OOD Lecture 6

Microsoft Visual Basic 2005: Reloaded

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later.

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

DESIGN PATTERN - INTERVIEW QUESTIONS

GoF Design Pattern Categories

Object Oriented Paradigm

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

Design Patterns. (and anti-patterns)

What is Design Patterns?

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng

Design Patterns! Acknowledgements!

Design Patterns Reid Holmes

26.1 Introduction Programming Preliminaries... 2

Object Oriented. Analysis and Design

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Chair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 10

What is Design Patterns?

If we aren t supposed to program to an implementation then how can we actually create new things? Reptile reptile = new Turtle(); Software Engineering

Design Pattern and Software Architecture: IV. Design Pattern

Final Exam Review (extended)

Egon Borger (Pisa) Capturing Design Pattern Abstractions by ASMs

Design for change. You should avoid

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Using Design Patterns in Java Application Development

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Cloning Enums. Cloning and Enums BIU OOP

Material and some slide content from: - GoF Design Patterns Book. Design Patterns #1. Reid Holmes. Lecture 11 - Tuesday October

Component ConcreateComponent Decorator ConcreateDecoratorA ConcreteDecoratorB

Development and Implementation of Workshop Management System Application to Explore Combing Multiple Design Patterns

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Second Midterm Review

Adapter pattern. Acknowledgement: Freeman & Freeman

Programming II (CS300)

COSC 3351 Software Design. Design Patterns Behavioral Patterns (II)

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

(Factory Method) (Intent) (Motivation) (instantiate) (defer) f. (application) (application) ƒ (document) ¾ (application-specific)

Programming II (CS300)

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Creational Patterns. George Blankenship

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

CSC207H: Software Design Lecture 6

Design Patterns. Structural Patterns. Oliver Haase

Lecture 5: Inheritance

Abstract Class & Interface: Two Villains of Every Interview - Part 1

ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns

The Proxy Pattern. Design Patterns In Java Bob Tarr

I, J. Key-value observing (KVO), Label component, 32 text property, 39

Proxy Design Pattern

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

Design Patterns Reid Holmes

Pro Objective-C Design Patterns for ios

Template Method. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 24 11/15/2007. University of Colorado, 2007

Transcription:

Comp435 Object-Oriented Design Week 11 Computer Science PSU HBG 1 Define an interface for creating an object Let subclasses decide which class to instantiate Defer instantiation to subclasses Avoid the creation of specific objects from framework High-level framework Application-specific objects to create is not known Use abstract classes» Define and maintain relationship between objects Application Application-specific subclasses of the abstract class» Override the factory method 2 Cannot anticipate the objects to be created Want to let subclasses to specify details of objects to be created Localize the creation of various objects Product Creator FactoryMethod() AnOperation() product = FactoryMethod() ConcreteProduct ConcreteCreator FactoryMethod() return new ConcreteProduct 3 4 Product / ConcreteProduct Creator / ConcreteCreator Creator relies on ConcreteCreator ConcreteCreator Override the factory method of Creator Returns an instance of ConcreteProduct Provide hooks for subclasses Flexibility on creating objects Connect parallel class hierarchies 5 6 1

Parallel Class Hierarchies Figure Manipulator LineFigure TextFigure LineManipulator TextManipulator 7 8 Without violating encapsulation, capture and externalize an object s internal state so that the object can be restored to this state later Want to store private state information of object Ex: support UNDO operation Want to avoid violating encapsulation Object s internal state should be available Object s internal state should not be visible to other objects Solution Use an object that stores snapshot of another object 9 A snapshot of whole/part of an object s state must be saved A direct interface to obtaining the state may expose internal implementation 10 Originator Set( m) Create() state return new (state) GetState() SetState() state state = m GetState() memento Caretaker 11, Originator, Caretaker Caretaker Requests a memento from an originator Holds it for a time Passes it back to the originator Originator Creates a memento upon Caretaker s request Sets the memento s state with its current state Retrieves the memento s state to restore its state Passive object 12 2

Preserves encapsulation boundaries Simplifies Originator May be expensive Hidden cost to Caretaker 13 14 Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype Want to reduce number of classes Ex: Building car engines Have common structures (material, shape, etc) Some attributes are different (4 valves vs 6 valves, etc)» Use inheritance: leads to class cluttering 15 Classes to instantiate are specified at run time Want to avoid parallel class hierarchy of factories Instances of a class can have one of only a few different combinations of state 16 Operation() p=prototype Concrete1 Concrete2 / Concrete asks a prototype to clone itself return copy of self return copy of self 17 18 3

Adding / removing products at run-time Specifying new objects by varying values Specifying new objects by varying structures Reduced subclassing Shallow copying Default copy constructor Deep copying Define your own copy constructor 19 20 Provide a surrogate or placeholder for another object to control access to it Need a more versatile or sophisticated reference than a simple pointer Control access to the actual objects by authentication Cache results from actual object for faster access Lazy initialization of expensive objects 21 Remote proxy Local representative for an object in a different address space Virtual proxy Lazy creation of expensive objects on demand Protection proxy Controlled access to the original object for protection Smart reference Additional actions when an object is accessed 22 RealSubject realsubject Subject realsubject Subject / RealSubject forward requests to RealSubject when appropriate 23 24 4

Introduces a level of indirection Remote proxy Disguise remote objects as local objects Virtual proxy Perform optimization such as lazy creation Protection proxy / smart reference Allow additional housekeeping when object is accessed 25 26 5