Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2009ACS-3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (Simple Factory) Prototype.

Similar presentations


Presentation on theme: "Fall 2009ACS-3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (Simple Factory) Prototype."— Presentation transcript:

1 Fall 2009ACS-3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (Simple Factory) Prototype Singleton These are creational patterns for the instantiation process Help to make a system independent of how its objects are created They hide how instances of classes are created GoF Patterns (Aside)

2 Fall 2009ACS-3913 R McFadyen2 Simple Factory Problem: who should be responsible for creating objects when there are special considerations such as complex creational logic, … Solution: create a Pure Fabrication object called a Factory that handles the creation. (The factory creates objects.) E.g. Which adapters should exist when NextGenPOS is running? The text presents a class that determines which adapters will be instantiated. Simple Factory Pattern

3 Fall 2009ACS-3913 R McFadyen3 Textbook example The NextGen POS system supports several kinds of 3 rd party services. For example: tax calculators such as TaxMaster and Good As Gold, account packages such as SAP and Great Northern. The support is provided through “adapters”. The text is concerned with determining the class that should create the required adapters. Choosing a class in the domain model will lower the cohesion of that class. Instead we apply pure fabrication, and using the Simple Factory Pattern, we have a Factory class that has the responsibility to create such adapter objects. Simple Factory Pattern

4 Fall 2009ACS-3913 R McFadyen4 Textbook example ServicesFactory is a class that is responsible for creating the various adapters required in NextGenPOS. It is a factory. Simple Factory Pattern ServicesFactory accountingAdapter:… inventoryAdapter:… taxCalculatorAdapter:… getAccountingAdapter():… getInventoryAdapter():… getTaxCalculatorAdapter():… A new class to add to our model

5 Fall 2009ACS-3913 R McFadyen5 Textbook example Suppose an external source contains the names of the adapters that are to be used. This source is available at runtime. ServicesFactory accesses this source and instantiates the correct adapter objects. Different adapters will be instantiated for different NextGenPOS systems. Simple Factory Pattern ServicesFactory accountingAdapter:… inventoryAdapter:… taxCalculatorAdapter:… getAccountingAdapter():… getInventoryAdapter():… getTaxCalculatorAdapter():…


Download ppt "Fall 2009ACS-3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (Simple Factory) Prototype."

Similar presentations


Ads by Google