| Author |
advantages of factory methods
|
saikrishna cinux
Ranch Hand
Joined: Apr 16, 2005
Posts: 689
|
|
what are the advantages of factory methods ? and when should i need to use them?
|
A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12920
|
|
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
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Rick O'Shay
Ranch Hand
Joined: Sep 19, 2004
Posts: 531
|
|
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
Joined: Apr 16, 2005
Posts: 689
|
|
thanks for ur valuable site links (resources) cinux
|
 |
Kai Witte
Ranch Hand
Joined: Jul 17, 2004
Posts: 354
|
|
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 ]
|
Kai Witte's business website Kai Witte's private homepage Mock exam / preparation kit reviews
|
 |
saikrishna cinux
Ranch Hand
Joined: Apr 16, 2005
Posts: 689
|
|
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
|
 |
Craig Tyler
Ranch Hand
Joined: Jan 15, 2006
Posts: 52
|
|
|
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.
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
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.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: advantages of factory methods
|
|
|