wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes confused with Design patterns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "confused with Design patterns" Watch "confused with Design patterns" New topic
Author

confused with Design patterns

Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
What is the difference between Factory pattern and Factory method pattern.
Example: 1
A class has a method getObject( String type).
This method returns one of the subclasses based on the type. Is this a Factory pattern or Factory method pattern.
Example 2:
A class has a method getObject(). A is an interface and b and c implement A.
This method returns objects of the subclass(b). Is this a Factory pattern or Factory method pattern.
I am not able to identify the patterns for the above examples. Please clarify.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I didn't know that there was two different patterns like that.
Now there are two Factory patterns, but they are called Factory and Abstract Factory. One is concrete and the other is really a Factory interface, meaning the subclasses of this Factory implements which classes to return when the interface is implemented.
In the regular Factory pattern, it already knows which type of classes it will return.
You will us the Factory and not the Abstract Factory patterns.
Example one to me looks like the Factory pattern, where Example two looks like it is trying to explain the Abstract Factory pattern.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
Thanks Mark. The following link discuss about the Factory Method Pattern.1. Factory Method Pattern
According to this, does example 1 fall under factory method pattern. Please clarify. I am confused.
2.
Factory method
[ April 24, 2003: Message edited by: Saraswathy Krishnamoorth ]
[ April 24, 2003: Message edited by: Saraswathy Krishnamoorth ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Again an Abstract Factory, is one that is really just the interface of a Factory class.
The other is the implemented Factory.
For example
Abstract Factory

As you can see in the above there is no actual implementation of this interface.
Now the Factory/FactoryMethod pattern is an actual implementation.

Hope that clears it up for you.
Mark
[ April 26, 2003: Message edited by: Mark Spritzler ]
Saraswathy Krishnamoorth
Ranch Hand

Joined: Mar 07, 2003
Posts: 73
Thanks Mark.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729


Can't be an interface, got implementation.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

er sorry, I meant to change the name of that class. I will do that now.
Mark
 
Don't get me started about those stupid light bulbs.
 
subject: confused with Design patterns
 
Similar Threads
Problem in polymorphism
Covariant problem
getInstance()
Help - Please explain
LocalSessionFactoryBean is not a sessionfactory instance