Design patterns - Abstract Factory Pattern

2,605 views
2,434 views

Published on

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.

Published in: Technology, Business
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
2,605
On SlideShare
0
From Embeds
0
Number of Embeds
36
Actions
Shares
0
Downloads
76
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Design patterns - Abstract Factory Pattern

  1. 1. QmPe initiativeABSTRACT FACTORY PATTERN explained ! Prepared by Annamalai C Copyright 2006-2011
  2. 2. 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 likeChinese, Indian, Continental.Abstract Factory Pattern is a Creational Pattern.Similar to Factory Pattern it is Object Creation without exposing “HOW” ? Copyright 2006-2011
  3. 3. Abstract 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 Order 2 Creates the Dish 3 Outsources to Chef 4 Delivers the Dish Copyright 2006-2011
  7. 7. How Factory Pattern works in Java ? public Food getFood(String name) { if (name.equals("Dosa")) { IndianFactory factory = new IndianFactory(); 1 return factory.getFood(name); } else if (name.equals("Noodles")) { ChineseFactory factory = new ChineseFactory(); return factory.getFood(name); }KitchenFactory factory = new KitchenFactory(); Return null;}Food dosa = factory.getFood("Dosa"); 2dosa.print(); Create food from Respective Factory ClassFood noodles = factory.getFood("Noodles");noodles.print(); 3 Food 4 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

×