design patterns - abstract factory pattern

8
ABSTRACT FACTORY PATTERN explained ! Prepared by Annamalai Copyright 2006-2011 QmPe initiative

Upload: annamalai-c

Post on 25-May-2015

1.709 views

Category:

Technology


1 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: Design patterns  - Abstract Factory Pattern

ABSTRACT FACTORY PATTERN explained !

Prepared by Annamalai C

Copyright 2006-2011

QmPeinitiative

Page 2: Design patterns  - Abstract Factory Pattern

Copyright 2006-2011

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 like Chinese, Indian, Continental.

Abstract Factory Pattern is a Creational Pattern.Similar to Factory Pattern it is Object Creation without exposing “HOW” ?

Page 3: Design patterns  - Abstract Factory Pattern

Copyright 2006-2011

Abstract Factory Pattern in Java

Page 4: Design patterns  - Abstract Factory Pattern

Copyright 2006-2011

Real Life vs Java Object

Factory

Kitchen

Page 5: Design patterns  - Abstract Factory Pattern

Copyright 2006-2011

Real Life vs Java Object

Page 6: Design patterns  - Abstract Factory Pattern

Copyright 2006-2011

How Factory Pattern works in Real Life ?

1 Orders a Dish from Menu

2Receives the OrderCreates the Dish

4 Delivers the Dish3 Outsources to Chef

Page 7: Design patterns  - Abstract Factory Pattern

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")) { IndianFactory factory = new IndianFactory(); return factory.getFood(name);} else if (name.equals("Noodles")) { ChineseFactory factory = new ChineseFactory(); return factory.getFood(name);}Return null;}

1

4

Food

Dosa Noodles

2

3

Create food from Respective Factory Class

Page 8: Design patterns  - Abstract Factory Pattern

Copyright 2006-2011

QmPeinitiative

THANK YOU

Please visit www.eclipseinclips.com | www.ancitconsulting.com

Write to us on [email protected]