design patterns - abstract factory pattern
DESCRIPTION
This presentation is part of the Design Pattern Series. Presentation explains the use of Abstract Factory Pattern comparing it against a real life situation and then showcasing the Java implementation of the same.TRANSCRIPT
ABSTRACT FACTORY PATTERN explained !
Prepared by Annamalai C
Copyright 2006-2011
QmPeinitiative
Copyright 2006-2011
Abstract Factory Pattern in Real LifeAbstract Factory Pattern is similar to Sub Contracting in real world.Basically delegating the creation of Objects to expert Factories-----------------------------------Orders in a restaurant are received by a Kitchen.Then are assigned to Special Chefs like Chinese, Indian, Continental.
Abstract Factory Pattern is a Creational Pattern.Similar to Factory Pattern it is Object Creation without exposing “HOW” ?
Copyright 2006-2011
Abstract Factory Pattern in Java
Copyright 2006-2011
Real Life vs Java Object
Factory
Kitchen
Copyright 2006-2011
Real Life vs Java Object
Copyright 2006-2011
How Factory Pattern works in Real Life ?
1 Orders a Dish from Menu
2Receives the OrderCreates the Dish
4 Delivers the Dish3 Outsources to Chef
How Factory Pattern works in Java ?
Copyright 2006-2011
KitchenFactory factory = new KitchenFactory();Food dosa = factory.getFood("Dosa");dosa.print();
Food noodles = factory.getFood("Noodles");noodles.print();
public Food getFood(String name) { if (name.equals("Dosa")) { IndianFactory factory = new IndianFactory(); return factory.getFood(name);} else if (name.equals("Noodles")) { ChineseFactory factory = new ChineseFactory(); return factory.getFood(name);}Return null;}
1
4
Food
Dosa Noodles
2
3
Create food from Respective Factory Class
Copyright 2006-2011
QmPeinitiative
THANK YOU
Please visit www.eclipseinclips.com | www.ancitconsulting.com
Write to us on [email protected]