Factory Method Pattern
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
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.
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?
Pizza Store Example
Encapsulate Object Creation Pull out object creation part (because it varies), encapsulate it in an object, call it a factory.
Use the Factory
Now Franchising the Store
What's wrong with this? Don't know if the same procedure Is followed in all stores.
Move Pizza Making Back to PizzaStore
Subclass decides
Factory Method Pattern