Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Factory Pattern and Factory Pattern

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd strongly encourage to check the Head First Design Patterns book by Freeman.
They have an entire chapter for these patterns.

HTH,

Carlos.
 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic