Download presentation
Presentation is loading. Please wait.
Published byBonnie Wade Modified over 8 years ago
1
Factory Method Pattern
2
Admin SCPI Patner Day Feb. 21 Lunch count Presentation (4-8 min.) Practice on Feb. 16. Morning availablity on Feb21 Brief overview of the problem Describe your approach to the problem UI mockups, prototype demo, key elements of design, architecture diagrams, design issues Focus on things that are interesting Progress to date
3
Factory Method Pattern Intent Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Also known as “Virtual Constructor” Motivating example A drawing application with DrawingApplication and DrawingDocument abstract classes. DrawingApplication needs to know which subclass of DrawingDocument to create.
4
Dealing with Class Instantiation Whenever we new a class, we are creating an instance of a concrete class. – Program to interface instead of implementation? – Build for change? – Open for extension, close to modification?
5
Pizza Store Example
6
Encapsulate Object Creation Pull out object creation part (because it varies), encapsulate it in an object, call it a factory.
7
Use the Factory
8
Now Franchising the Store
9
What's wrong with this? Don't know if the same procedure Is followed in all stores.
10
Move Pizza Making Back to PizzaStore
11
Subclass decides
13
Factory Method Pattern
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.