Design patterns - Factory Pattern

1,489 views

Published on

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.

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,489
On SlideShare
0
From Embeds
0
Number of Embeds
25
Actions
Shares
0
Downloads
43
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Design patterns - Factory Pattern

  1. 1. QmPe initiativeFACTORY PATTERN explained ! Prepared by Annamalai C Copyright 2006-2011
  2. 2. 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
  3. 3. Factory Pattern in Java Copyright 2006-2011
  4. 4. Real Life vs Java Object Factory Kitchen Copyright 2006-2011
  5. 5. Real Life vs Java Object Copyright 2006-2011
  6. 6. How Factory Pattern works in Real Life ? 1 Orders a Dish from Menu Receives the Name of the Dish 2 Creates the Dish 3 Delivers the Dish Copyright 2006-2011
  7. 7. How Factory Pattern works in Java ? public Food getFood(String name) { if (name.equals("Dosa")) { return new Dosa(); 1 } else if (name.equals("Noodles")) { return new Noodles(); } return null; }KitchenFactory factory = new KitchenFactory();Food dosa = factory.getFood("Dosa");dosa.print(); 2Food noodles = factory.getFood("Noodles");noodles.print(); Food 3 Dosa Noodles Copyright 2006-2011
  8. 8. THANK YOU Please visitwww.eclipseinclips.com | www.ancitconsulting.com Write to us on info@ancitconsulting.com QmPe initiative Copyright 2006-2011

×