12

Design Pattern - Abstract Factory

Embed Size (px)

DESCRIPTION

I wanna buy a car. I’ve limited budget. I wanna choose brand & model. I don’t want to take headache about wheel, air horn, steering, door and others parts of the car. I’m going to the show room. Now there are some modes within my budget like Toyota 2014 Corolla, Toyota RAV4 and so on. Technically now come to the point, if I choose any model from these, I don’t need to bother about the parts of the car. Here all models are like Abstract Methods. I mean here Toyota 2014 Corolla is an abstract Factory. Again Toyota RAV4 is also an abstract factory. I have many options like Toyota 2014 Corolla, Toyota RAV4 etc. I can choose Toyota 2014 Corolla or Toyota RAV4 (Abstract Factory). In the abstract Factory, there are couples of factory methods which will provide me entire dependent parts (object) of the car. Say, car has horns, wheel, steering and so on. Here Horns (i.e., IHorn interface) is a factory method because it will produce a product from its implementation like, Bad Boy Air Horn, Snail Air Horn etc. Wheel (i.e., IWheel interface) is another factory method cos it has several implementation like, Flat Black Wheel, Black Wheel etc. Similarly Steering (i.e., ISteering interface) has couples of implementation like Semi Black Color Steering, Black Color Steering etc. So, Abstract Factory creates all of these dependent auto mobile parts and provides a complete new car. Investigation sammary. Look at the car, it has lots of dependent parts. All of the parts are assembled into Abstract Factory. All of the parts are created separately from Factory Method. Now let’s look at the diagram. There are some interface classes of IHorn, IWheel & ISteering. Each of these interface Classes has couples of implementation classes. ICarFactory is an interface class and it has two implementation classes which will create more than one new objects (new instance). Let’s look at the diagram. I pass the Car model as a parameter into the constructor of the Car Show room class and this class creates couples of dependent objects families together into Assemble method. Abstract Factory is the right choice. Mail me if you need example source code. Now is the time to go for long driving..

Citation preview

Page 1: Design Pattern - Abstract Factory
Page 2: Design Pattern - Abstract Factory
Page 3: Design Pattern - Abstract Factory
Page 4: Design Pattern - Abstract Factory
Page 5: Design Pattern - Abstract Factory
Page 6: Design Pattern - Abstract Factory
Page 7: Design Pattern - Abstract Factory
Page 8: Design Pattern - Abstract Factory
Page 9: Design Pattern - Abstract Factory
Page 10: Design Pattern - Abstract Factory
Page 11: Design Pattern - Abstract Factory
Page 12: Design Pattern - Abstract Factory