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.
Injustice - Developers Among Us (SciFiDevCon 2024)
Design patterns - Abstract Factory Pattern
1. QmPe
initiative
ABSTRACT FACTORY PATTERN explained !
Prepared by Annamalai C
Copyright 2006-2011
2. Abstract Factory Pattern in Real Life
Abstract 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 like
Chinese, Indian, Continental.
Abstract Factory Pattern is a Creational Pattern.
Similar to Factory Pattern it is Object Creation without exposing “HOW” ?
Copyright 2006-2011
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. 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"); 2
dosa.print();
Create food from Respective Factory Class
Food noodles = factory.getFood("Noodles");
noodles.print();
3
Food
4
Dosa Noodles
Copyright 2006-2011
8. THANK YOU
Please visit
www.eclipseinclips.com | www.ancitconsulting.com
Write to us on info@ancitconsulting.com
QmPe
initiative
Copyright 2006-2011