Presentation is loading. Please wait.

Presentation is loading. Please wait.

Factory Method By Judith Mziray And Jerry Cipolla.

Similar presentations


Presentation on theme: "Factory Method By Judith Mziray And Jerry Cipolla."— Presentation transcript:

1 Factory Method By Judith Mziray And Jerry Cipolla

2 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 ??

3 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.

4 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

5 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.

6 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.

7 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.

8 Object and Instantiation Gun (object) -- shoot (instantiation) Grenade (object) - pull the pin (instantiation) Bazooka (object) – shoot (instantiation)

9 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.

10 Structure Special forces (YOU) Grenade Intelligence & Politicians Pull pin class Sub-class object instantiation

11 Questions ?????


Download ppt "Factory Method By Judith Mziray And Jerry Cipolla."

Similar presentations


Ads by Google