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
Joined: Apr 16, 2005
thanks for ur valuable site links (resources) cinux
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.
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