• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

confused with Design patterns

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saraswathy Krishnamoorth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Can't be an interface, got implementation.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
er sorry, I meant to change the name of that class. I will do that now.
Mark
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic