factory method l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Factory Method PowerPoint Presentation
Download Presentation
Factory Method

Loading in 2 Seconds...

play fullscreen
1 / 11

Factory Method - PowerPoint PPT Presentation


  • 309 Views
  • Uploaded on

Factory Method. By Judith Mziray And Jerry Cipolla. Overview. Big picture view of the Factory Method Participants of the Factory Method Case study/hypothetical Defining or classifying the elements within the hypothetical Pro’s and Con’s of the Factory Method

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Factory Method' - mervyn


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
factory method

Factory Method

By Judith Mziray

And

Jerry Cipolla

overview
Overview
  • Big picture view of the Factory Method
  • Participants of the Factory Method
  • Case study/hypothetical
  • Defining or classifying the elements within the hypothetical
  • Pro’s and Con’s of the Factory Method
  • Hypothetical applied to a diagram/structure
  • Questions ??
factory method big picture
Factory Method – Big Picture
  • Creates or manufactures objects, just like a real factory.
  • The factory method is used when its just not possible for a CLASS to predict what CLASS of OBJECTS will be needed and what exact INSTANTIATION or action is needed.
  • Class DELEGATES to a SUBCLASS which picks the appropriate object to instantiate, given the specific circumstances.
participants
Participants
  • Product – defines the interface of objects the factory method creates
  • ConcreteProduct – implements the Product interface
  • Creator – declares the factory method, which returns an object of type Product
  • ConcreteCreator – overrides the factory method to return an instance of a ConcreteProduct
factory method getting rid of the beauracracy
Factory Method- getting rid of the beauracracy
  • Hypothetical: Imagine you are a special forces soldier in a far off country. Intelligence and the politicians know something is going to happen within the operation. However, what specifically needs to happen must be decided on a split second decision. You can shoot your gun, you can shoot your bazooka, or you can throw a grenade. It just depends on what the enemy is doing, which cannot be predicted.
hypothetical continued
Hypothetical continued
  • Intelligence and the politicians must rely on your judgment.
  • Look at it this way, intelligence and the politicians are the classes, and you, the special forces soldier in the field, are the creator. Intelligence has delegated to you to pick the appropriate subclass that will instantiate the correct object. In other words, you pick the subclass to make the correct instantiation such as a gun that will shoot, a grenade and pull the pin, or a bazooka to shoot.
hypothetical defined
Hypothetical defined
  • Class - Politicians – delegating authority down the line
  • Class - Intelligence – delegating authority to you
  • Delegating Subclass/Creator – You, the special forces soldier, are the delegating subclass or creator that chooses which object to pick, the gun, the grenade, or the bazooka, which all will be instantiated.
object and instantiation
Object and Instantiation
  • Gun (object) -- shoot (instantiation)
  • Grenade (object) - pull the pin (instantiation)
  • Bazooka (object) – shoot (instantiation)
pro s and con s factory method
Pro’s and Con’s -Factory Method
  • Lets a class defer instantiation to subclasses
  • Eliminates the need to bind application-specific classes into your code
  • Disadvantage is sub-classing may become too complex or tedious for the client in later additions to the code.
structure
Structure

instantiation

class

Intelligence &

Politicians

Pull pin

Grenade

Special forces

(YOU)

Sub-class

object