Design patterns - Factory Pattern
Click here to load reader
-
Upload
annamalai-c -
Category
Technology
-
view
1.077 -
download
0
description
Transcript of Design patterns - Factory Pattern
FACTORY PATTERN explained !
Prepared by Annamalai C
Copyright 2006-2011
QmPeinitiative
Copyright 2006-2011
Factory Pattern in Real LifeKitchen in a Restaurant is similar to a Factory.It is the Production House of the Restaurant.-----------------------------------Customer places orders from a Menu, doesn’t really know how it gets prepared.In return to the order, gets a fully cooked dish for eating.
Factory Pattern is a Creational Pattern.It helps in Object Creation without exposing the details of Creation.
Copyright 2006-2011
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 Name of the DishCreates the Dish
3 Delivers the Dish
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")) { return new Dosa(); } else if (name.equals("Noodles")) { return new Noodles(); } return null;}
1
3
Food
Dosa Noodles
2
Copyright 2006-2011
QmPeinitiative
THANK YOU
Please visit www.eclipseinclips.com | www.ancitconsulting.com
Write to us on [email protected]