This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this the Factory Method?

 
Swerrgy Smith
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

There is a kind of method that is used quite often. I will use an example: suppose that we have 2 classes Man and Woman that extend class Human. And in another class HumanUtilities, we have:



Is the getInstance() method a Factory Method? If so, this method does not follow the definition of Factory Method Pattern: "Define an interface for creating an object, but let the classes that implement the interface decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses."

If this is not a factory method, what is this? I notice that this kind of method is used VERY OFTEN.

Thanks.
 
Swerrgy Smith
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can anyone help me?
 
Maxim Karvonen
Ranch Hand
Posts: 120
12
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to your definition, this is not a "factory method". Real "factory method" should use non-static non-final factory method. Even better if you create two classes and override or implement factory method in child.

Anyway, your example is a kind of "factory". And usually just mentioning "factory" will be sufficient in a non-academic environment. You can see concrete factory implementation in a code or in a diagram. You don't need to distinguish different kinds of factory in a high-level design. Hence you don't need detailed classification of "factories". You only need it when you study them (classify, calculate frequencies, etc...). And in this case better consult your teacher or buddies, because terms may vary slightly in different places.

And one more note. Overriding "factory method" in subclasses is usually not a good idea. Using pure interface (and passing an instance in constructor) usually will be more adaptable that having method hardcoded and overriden in some places.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic