Factory Method Pattern
  Shahriar Iqbal Chowdhury & Monjurul Habib
        Code Name: Remington



     http://www.facebook.com/groups/netter/
Why We need Factory? Caveman Example
The Solution
A specialist for the job
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.
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.
Factory Says

Define an interface for creating an object, but let subclasses decide which class to instantiate
Problem without Factory Method Pattern
Solution Applying Factory Method Pattern
Banking Account Management System
Object is created based on
configuration parameters
Violation of OCP
(Open Close
Principle of SOLID)
we will need to create a property that indicates type in each account class
Factory method pattern

Factory method pattern

Editor's Notes

  • #3 once upon a time caveman's were happy, their need was small, their hunting gear is big enough for their prey
  • #4 Soon their more mouth to feed, with that amount of hunting they can do only one thing!! Cutting... OR hunting bigger prey. Is that easy???
  • #5 Hummm, seems that idea didn't workout well.
  • #6 Its time to call the hunter and enjoy the meal :)
  • #9 The client is an object that requires an instance of another object for some purpose. Rather than creating the product instance directly, the client delegates this responsibility to the factory. Once invoked, the factory creates a new instance of the product, passing it back to the client. Put simply, the client uses the factory to create an instance of the product. 
  • #16 Use Reflection