Re: Is a static method sufficient to call it factory?
- From: Chris Smith <cdsmith@xxxxxxx>
- Date: Thu, 28 Jul 2005 08:03:07 -0600
<f.vivoli@xxxxxxxxx> wrote:
> Talking about factories why someone propose the way
>
> Factory.getInstance().createClass(aType);
>
> instead of simply
>
> Factory.createClass(aType);
[...]
> In the end, is a class with a static method eligible to be an use of a
> factory method pattern? It doesn't resemble the structure of the GOF
> pattern, since it doesn't use subclassing...
I think you're getting caught up in terminology here. Does it really
matter if the code fits under the umbrella name that the GoF book gives
to its pattern. Read design pattern books to broaden your repertoire of
design approaches, but attachment to names and classification is not the
point here.
Both of the approaches above can have advantages. The static factory
method is certainly easier; no argument there. For that reason, it's
probably best to use it when it meets your needs, unless you're
designing a potentially published API that might need additional
flexibility in the future. If you're writing published APIs, then some
degree of long-term planning is called for here, and you'll want to
think this through a bit more.
The advantage of the getInstance() approach arises when you're a bit
less coupled to the resulting code. It allows you to encapsulate the
entire interface to some external module within a single object, which
can then return the objects your code (or client) needs. At a minimum,
that ensures that you only have to look up the provider once, if you use
some sort of provider interface registration via properties files in
resources, etc. It also allows the service provider to maintain state
about the application's usage of it, and other things along those lines.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
.
- References:
- Is a static method sufficient to call it factory?
- From: f . vivoli
- Is a static method sufficient to call it factory?
- Prev by Date: Re: Java Programmer Needed NY
- Next by Date: Re: reading image files from applet -- newbie question
- Previous by thread: Re: Is a static method sufficient to call it factory?
- Next by thread: Re: Is a static method sufficient to call it factory?
- Index(es):
Relevant Pages
|