design patterns - factory pattern
DESCRIPTION
This presentation is part of the Design Pattern Series. Presentation explains the use of Factory Pattern comparing it against a real life situation and then showcasing the Java implementation of the same.TRANSCRIPT
![Page 1: Design patterns - Factory Pattern](https://reader037.vdocument.in/reader037/viewer/2022100507/5584ad62d8b42afd5b8b4f65/html5/thumbnails/1.jpg)
FACTORY PATTERN explained !
Prepared by Annamalai C
Copyright 2006-2011
QmPeinitiative
![Page 2: Design patterns - Factory Pattern](https://reader037.vdocument.in/reader037/viewer/2022100507/5584ad62d8b42afd5b8b4f65/html5/thumbnails/2.jpg)
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.
![Page 3: Design patterns - Factory Pattern](https://reader037.vdocument.in/reader037/viewer/2022100507/5584ad62d8b42afd5b8b4f65/html5/thumbnails/3.jpg)
Copyright 2006-2011
Factory Pattern in Java
![Page 4: Design patterns - Factory Pattern](https://reader037.vdocument.in/reader037/viewer/2022100507/5584ad62d8b42afd5b8b4f65/html5/thumbnails/4.jpg)
Copyright 2006-2011
Real Life vs Java Object
Factory
Kitchen
![Page 5: Design patterns - Factory Pattern](https://reader037.vdocument.in/reader037/viewer/2022100507/5584ad62d8b42afd5b8b4f65/html5/thumbnails/5.jpg)
Copyright 2006-2011
Real Life vs Java Object
![Page 6: Design patterns - Factory Pattern](https://reader037.vdocument.in/reader037/viewer/2022100507/5584ad62d8b42afd5b8b4f65/html5/thumbnails/6.jpg)
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
![Page 7: Design patterns - Factory Pattern](https://reader037.vdocument.in/reader037/viewer/2022100507/5584ad62d8b42afd5b8b4f65/html5/thumbnails/7.jpg)
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
![Page 8: Design patterns - Factory Pattern](https://reader037.vdocument.in/reader037/viewer/2022100507/5584ad62d8b42afd5b8b4f65/html5/thumbnails/8.jpg)
Copyright 2006-2011
QmPeinitiative
THANK YOU
Please visit www.eclipseinclips.com | www.ancitconsulting.com
Write to us on [email protected]