factory v/s abstract factory

hi experts



i want to know what exactly is difference between "factory design pattern" and abstract factory design pattern"


is it true that abstract factory and factory design patterns are used to gether, and factory design pattern instantiates
abstract factory design pattern.

a short n clear description would greatly help..

please do not redirect me to websites such as      http://c2.com/cgi/wiki?AbstractFactoryVsFactoryMethod

i just need a clear picture of whats going on..

thanks in advance,
J
LVL 10
jaggernatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
Abstract Factory - provide an interface for crreating families of related or dependant objects without specifying their concrete classes

Factory Metod - define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
0
jaggernatAuthor Commented:
can you please give a short example.

thanks for prompt res,
J
0
objectsCommented:
AF - a gui toolkit could use this pattern to create widgets, the abstract factory would define methods for creating various types of widgets avaiolable. Each L&F (eg. Windows, Motif) would provide an implementation of this factory to return the widget subclass for that l&f thus making the client independant of the l&f

FM - an application framework that deals with different document types. In this case the particulkar Document type to create is application specific and the framework has no way of knowing what type of document is to be created (it only knows about abstract document class). So instead application subclasses redefine the factory method to return the appropriate document subclass.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Mayank SAssociate Director - Product EngineeringCommented:
>> please do not redirect me to websites such as      

I could've copy-pasted the whole stuff, but actually there's good explanation there :)
0
CEHJCommented:
"provide an interface for crreating families of related or dependant objects without specifying their concrete classes"

That's why i told you earlier (largely ignored) your abstract soup factory should not be instantiating (or promising to instantiate) concrete soups
0
sanjuskCommented:
The Factory Method provides a simple decision making class that
returns one of several possible subclasses of an abstract base class depending
on the data that are provided.
The Abstract Factory Method provides an interface to create and
return one of several families of related objects.

I suggest
http://www.patterndepot.com/put/8/DesignJava.PDF get thiis file. it explain thing very clearly. You justs need too study first few page.that it.

If still this book doesn't help then i'll try to give an example
regards
Sanjeev
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim CakalicSenior Developer/ArchitectCommented:
Hi, jaggernat. Here's an explanation I gave once a long time ago to try to help someone else differentiate the three factory design patterns. Maybe it will help you.

Simple Factory creates an instance of one of several possible classes depending on the data provided to it. It says, in effect, "You give me some criteria and I will decide how to make an appropriate object. You shouldn't care what the class is of the object I give you -- they will all offer the same services." As a silly example, suppose you wanted to construct a Vehicle object based on the number of wheels that it has. Which object you get is irrelevant for your purposes. You might define it like this:

public class VehicleFactory {
   public Vehicle getVehicle(int wheels) {
       switch (wheels) {
       case 1:  return new Unicycle();
       case 2:  return new Bicycle();
       case 3:  return new Tricycle();
       case 4:  return new Carriage();
       default: return null;
   }
}

interface Vehicle {
   // common methods
}

public class Unicycle implements Vehicle {
}
public class Bicycle implements Vehicle {
}
public class Tricycle implements Vehicle {
}
public class Carriage implements Vehicle {
}

So now, based on the data supplied, this Vehicle factory can decide which subclass of a single hierarchy to instantiate. The client knows that it is working with a factory.

Factory Method is a subtle extension of this idea. The difference is that there is no real factory decision point at which it is determined to construct one class or another as in Simple Factory. Instead, there are two hierarchies of classes at work. Specific instances of classes from one hierarchy are created as determined by the needs of the client program. Which specific class from the second heirarchy is created is decided by each class from the first hierarchy. Totally clear? How about another example.

Extending the previous example, I'm going to define two class hierarchies. The first will be Vehicle and the second will be SteeringMechanism. A picture would be good but I haven't figured out how to post pictures to the forum. In lieu of a picture, here are some abbreviated class definitions.

public abstract class Vehicle {
   public abstract SteeringMechanism getSteeringMechanism();
}
public class Unicycle extends Vehicle {
   public SteeringMechanism getSteeringMechanism() {
       return new SeatOfPants();
   }
}
public class Bicycle extends Vehicle {
   public SteeringMechanism getSteeringMechanism() {
       return new Handlebars();
   }
}
public class Tricycle extends Vehicle {
   public SteeringMechanism getSteeringMechanism() {
       return new Handlebars();
   }
}
public class Car extends Vehicle {
   public SteeringMechanism getSteeringMechanism() {
       return new SteeringWheel();
   }
}

public abstract class SteeringMechanism {
   // some useful abstract method definitions
}
public class SeatOfPants extends SteeringMechanism {
   // implementation
}
public class Handlebars extends SteeringMechanism {
   // implementation
}
public class SteeringWheel extends SteeringMechanism {
   // implementation
}

In this example, the decision about which Vehicle subclass to instantiate determines which SteeringMechanism class will be instantiated. And, as you can see, there is not necessarily a one-to-one correspondence between classes in the two hierarchies. Both Bicycle and Tricycle instantiate a Handlebar class as the SteeringMechanism. The pattern is called Factory Method because the, well, the factory is implemented in a method. Note that each Vehicle class implements its own getSteeringMechanism method? This method is actually the "factory method" of the pattern.

Finally, Abstract Factory is about creating factories for families of objects. Instead of being able to create just one kind of object, each concrete factory can greate several kinds of objects. Each concrete factory implements a common interface so that after the specific concrete factory is selected the application can use it without concern as to which factory it is using. That is what makes this an "Abstract Factory". GUI toolkits are the classic example here. Lets say you want to support Motif, Windows, and Macintosh GUIs which can each display a ListBox, a TextField, and a Label. First you'd define interfaces and/or abstract implementations for Toolkit, ListBox, TextField, and Label. The Toolkit is the abstract factory in this case perhaps with methods for createListBox, createTextField, and createLabel. Then you'd implement the concrete classes for these interfaces, three of each: MotifToolkit, MotifListBox, MotifTextField, and MotifLabel for Motif and similar for Windows and Mac. Once the application had selected the UI factory, the it could call the create methods without concern for which specific family of objects was being returned.

Best regards,
Jim Cakalic
0
Mayank SAssociate Director - Product EngineeringCommented:
I thought objects also deserved some points here.
0
jaggernatAuthor Commented:
is it? my appologies to you( and objects) if i was wrong in judging points. actually the pdf which sanjusk gave me was clear with easy to understand examples.

thanks
J
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.