Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Design patterns - Factory Pattern

1,536 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
  • Be the first to comment

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

×