• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

advantages of factory methods

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what are the advantages of factory methods ?
and when should i need to use them?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find a lot of information by searching with (for example) Google. Within 10 seconds you'll find this if you search for "factory method":

The Factory Method (Creational) Design Pattern
JavaWorld: Factory methods
Java Practices: Factory methods
Pattern Summaries: Factory Method
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am going to assume you know how to google and that you are rather looking for a point of view that you can interact with. Moreover, every question on this forum could be preceded by "you can get information from google"; so it is pointless to suggest that.

Factory methods insulate your application from custom code. Creating custom versions of an application is therefore simplified.

Assume you have several customers and they all have specialized needs. Sprinkling your code with conditional statements everywhere there was a customer variance would create a maintenance nightmare. Instead, you can capture variances in a class or set of classes with a standard interface. Factory methods are then used to select the appropariate sub-type at runtime. The rest of your application is unaware that it's running a specialized version of the application. The same application can support an infinite variety of implementations withou change.

Note that you still have the conditional statement that decides which class to instantiate, however, it's all neatly packaged inside a factory method that creates
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for ur valuable site links (resources)
cinux
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

I recently wrote a Design Principles article where I also state my opinion regarding the applicability of factory methods (section "Encapsulate instance control").

Kai
[ February 06, 2006: Message edited by: Kai Witte ]
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i 've seen all the links.
but i ain't getting the actual concept ?? :roll:
can anyone provide me an example program for the implementation of factory methods
thanx in advance
cinux
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take the Calendar class as an example. It uses a factory method to give you a calendar instance based on what your default locale would use. So, while you always use a Calendar reference variable, the actual class of the object will vary.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Craig Tyler:
Take the Calendar class as an example. It uses a factory method to give you a calendar instance based on what your default locale would use. So, while you always use a Calendar reference variable, the actual class of the object will vary.



Notice that this is *not* the Factory Method design pattern. The design pattern involves a polymorphic method call inside a class hierarchy to create an object.
reply
    Bookmark Topic Watch Topic
  • New Topic