factory pattern

15
Factory Method Pattern Shahriar Iqbal Chowdhury & Monjurul Habib Code Name: Remington http://www.facebook.com/groups/netter/

Upload: monjurul-habib

Post on 28-Jun-2015

160 views

Category:

Technology


0 download

DESCRIPTION

1. Factory Method Pattern Shahriar Iqbal Chowdhury & Monjurul Habib Code Name: Remington http://www.facebook.com/groups/netter/ 2. Why We need Factory? Caveman Example 3. The Solution 4. A specialist for the job 5. Factory Pattern Method Basics• Creational Pattern• Which object to create• It lets a class defer instantiation to subclasses.• Absolutely all constructors should be private or protected• Also known as Virtual Constructor. 6. When to consider?• When we have a class that implements an interface but not sure which object, which concrete instantiation / implementation need to return.• When we need to separate instantiation from the representation.• When we have lots of select and switch statements for deciding which concrete class to create and return. 7. Factory SaysDefine an interface for creating an object, but let subclasses decide which class to instantiate 8. Problem without Factory Method Pattern 9. Solution Applying Factory Method Pattern 10. Banking Account Management System 11. Object is created based onconfiguration parameters 12. Violation of OCP(Open ClosePrinciple of SOLID) 13. we will need to create a property that indicates type in each account class

TRANSCRIPT

Page 1: Factory Pattern

Factory Method Pattern

Shahriar Iqbal Chowdhury & Monjurul Habib

                                Code Name: Remington

                       

                            http://www.facebook.com/groups/netter/

Page 2: Factory Pattern

Why We need Factory? Caveman Example

Page 3: Factory Pattern
Page 4: Factory Pattern

The Solution

Page 5: Factory Pattern

A specialist for the job

Page 6: Factory Pattern

Factory Pattern Method Basics

• Creational Pattern• Which object to create• It lets a class defer instantiation to subclasses.• Absolutely all constructors should be private or protected• Also known as Virtual Constructor.

Page 7: Factory Pattern

When to consider?

• When we have a class that implements an interface but not sure which object, which concrete instantiation / implementation need to return.• When we need to separate instantiation from the representation.• When we have lots of select and switch statements for deciding which concrete class to create and return.

Page 8: Factory Pattern

Factory Says

Define an interface for creating an object, but let subclasses decide which class to instantiate

Page 9: Factory Pattern

Problem without Factory Method Pattern

Page 10: Factory Pattern

Solution Applying Factory Method Pattern

Page 11: Factory Pattern

Banking Account Management System

Page 12: Factory Pattern

Object is created based on configuration parameters

Page 13: Factory Pattern

Violation of OCP (Open Close Principle of SOLID)

Page 14: Factory Pattern

we will need to create a property that indicates type in each account class

Page 15: Factory Pattern