Object Oriented Design Patterns Continuous Assessment 2

19
Prototype + Factory Object Oriented Design Patterns Continuous Assessment 2

description

Prototype + Factory. Object Oriented Design Patterns Continuous Assessment 2. Summary of Problems and Solutions. Prototype. Detailed Presentation of most interesting problem. Problem. Concrete StoreObject creation ( DrinkBrand and Coin ) logic are wrapped inside PropertyLoader . - PowerPoint PPT Presentation

Transcript of Object Oriented Design Patterns Continuous Assessment 2

Page 1: Object Oriented Design Patterns  Continuous Assessment 2

Prototype + Factory

Object Oriented Design Patterns Continuous Assessment 2

Page 2: Object Oriented Design Patterns  Continuous Assessment 2

Summary of Problems and Solutions

Page 3: Object Oriented Design Patterns  Continuous Assessment 2

Sno Problem Solution Pattern

1 Drink Store Item Quantity Display Synchronization

Observer

2 Initializing Stores and creation of StoreObjects Prototype + Factory

3 Vending Machine Control State State

4 Enter Coins Chain of Responsibility

Page 4: Object Oriented Design Patterns  Continuous Assessment 2

PROTOTYPE

Detailed Presentation of most interesting problem

Page 5: Object Oriented Design Patterns  Continuous Assessment 2

Problem

• Concrete StoreObject creation (DrinkBrand and Coin) logic are wrapped inside PropertyLoader.

– Inflexibility in creation logic.– Accommodating new kinds of StoreObjects is difficult.– If the current file based database is changed to other

persistent mechanisms, then the entire logic behind creation needs to be re-written.

Page 6: Object Oriented Design Patterns  Continuous Assessment 2

Caveats

• While we are aware that problems exist among the following areas, those are not addressed in the current solution

– Two different property loaders still exist.– StoreItem objects are still constructed from

property loaders

Page 7: Object Oriented Design Patterns  Continuous Assessment 2

Analysis of problem

• Creational and initialization logic for an object exists outside of the object.

• This is a CREATIONAL problem

Page 8: Object Oriented Design Patterns  Continuous Assessment 2

Candidate Design Patterns

• Prototype– Specify the kinds of objects to create using a prototypical

instance and create new objects by copying this prototype.• Factory method– Define an interface for creating an object, but let

subclasses decide which class to instantiate.• Abstract Factory– Provide an interface for creating families of related or

dependent objects without specifying their concrete classes

Page 9: Object Oriented Design Patterns  Continuous Assessment 2

Abstract Factory applicability

• The system should be independent of how its products are created, composed andrepresented

• The system should be configured with one of multiple families of products

• A family of related product objects is designed to be used together and you need to enforce this constraint

Page 10: Object Oriented Design Patterns  Continuous Assessment 2

Factory method applicability

• 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 class to delegate

Page 11: Object Oriented Design Patterns  Continuous Assessment 2

Prototype applicability

• The system should be independent of how its products are created, composed and represented

• The classes to instantiate are specified at runtime

• Avoid building a class hierarchy of factories that parallels the class hierarchy of products

Page 12: Object Oriented Design Patterns  Continuous Assessment 2

Initialize CashStore

Page 13: Object Oriented Design Patterns  Continuous Assessment 2

Initialize DrinkStore

Page 14: Object Oriented Design Patterns  Continuous Assessment 2

Static View – Status quo

Page 15: Object Oriented Design Patterns  Continuous Assessment 2

• Concrete StoreObject creation (DrinkBrand and Coin) logic are wrapped inside PropertyLoader.

– Inflexibility in creation logic.– Accommodating new kinds of StoreObjects is difficult.

Problems come in bunches - revisit

Page 16: Object Oriented Design Patterns  Continuous Assessment 2

Participant mapping

Page 17: Object Oriented Design Patterns  Continuous Assessment 2

New static view

Page 18: Object Oriented Design Patterns  Continuous Assessment 2

Modified Initialize Store - Cash

Page 19: Object Oriented Design Patterns  Continuous Assessment 2

DEMO