wood burning stoves 2.0*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Abstract Factory Pattern and Factory Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Abstract Factory Pattern and Factory Pattern" Watch "Abstract Factory Pattern and Factory Pattern" New topic
Author

Abstract Factory Pattern and Factory Pattern

Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 215
I am really confused with these patterns. I fianlly decided to write it simple words.
Please correct me if i am wrong?

1) Factory Pattern
2) Abstract factory Pattern



Factory Pattern:If we have super class and n sub classes,then based on that data we provide it return object of one sub classes
for ex
Vehicle=> Super class
1) Small Cars=> Subclass 1
2) Meduim Size Cars=> Subclass 2
3) Big Cars=> Subclass 3

Based on data provided it will return object of Small Cars or Meduim Size Cars or Big Cars


Abstract Factory Pattern:
1) It is used to create the family of related objects
2) based on the data it first finds the family, then it uses factory pattern within the family to return the object of one of the subclass.
(It depends on factory pattern to complete its architecture).

3)


Vehicle=> Super class
1) Small Cars=> family1=>suclasses =>maruti 800,zen,alto

2) Meduim Size Cars=> family2=>suclasses =>esteem,swift

3) Big Cars=> family3=>suclasses 3=>honda city,honda accord


We have Vechicle as a super class and Small Cars,Meduim Size Cars,Big Cars as families and their corresponding subclasses within the family.

Abstract factory pattern will first find the family.After finding the family, Abstract factory pattern will then use then factory pattern to return required
object.



Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

I'd strongly encourage to check the Head First Design Patterns book by Freeman.
They have an entire chapter for these patterns.

HTH,

Carlos.


SCSA, OCA, SCJP 5.0, SCJD http://www.linkedin.com/in/carlosamorillo
Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 215
I am preparing myself for interview and i can't devote time in reading HFDP.So need the reply urgently and know whether my anaology is correct?.
Please help me urgently


sriram sankar
Ranch Hand

Joined: Feb 26, 2008
Posts: 43
amolpalekar kadolkar wrote:I am preparing myself for interview and i can't devote time in reading HFDP.So need the reply urgently and know whether my anaology is correct?.
Please help me urgently




Abstract Factory is used for creating family of objects/ or in other words create's factories which inturn create objects.

For Eg: You have Base Abstract class called CarFactory

FordFactory extends CarFactory
GMFactory extends CarFactory
BenzFactory extends CarFactory

Specialized factories are created using this pattern.

Factory method is used in Abstract Factory to create Factories.


SCJP 1.5 , SCBCD 5.0, SCEA 5.0
 
 
subject: Abstract Factory Pattern and Factory Pattern
 
Similar Threads
Factory Vs Abstract Factory Pattern
Factory Pattern - help needed !!!!
Abstract Factory Pattern and Factory Method Pattern
Abstract Factory vs Factory pattern
upper bound wildcard is readonly but lower bound are not