Frankly, I have no idea what the term "Singleton Factory Object" is supposed to mean. Where did you get that question from?
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
I reckon it just means a Singleton which is also a factory (ie. it has a public method which can be called to "create" other objects.) That way you get a Singleton which also acts as an Abstract Factory for other objects.
This seems to be one of the more common uses for Singleton.
If the Factory is singleton, then there can only exist one factory object.
So then if this Factory object has a field int numOfThingsMade. Then this value will be a true reflection of how many things have been made.
If the Factory was NOT singleton, then...
Would require you to do f1.numOfThingsMade+f2.numOfThingsMade ( =3 ) to get the total, whereas the singleton factory has special powers since you would just call SingletonFactory.getInstance().numOfThingsMade, and get 3.
Have I got the right idea? Thanks [ May 14, 2007: Message edited by: colin shuker ]
Thanks, continuing from above, I need the Factory to create Shape (an Interface) objects, such as Circle,Triangle,Rectangle(implements Shape).
But the Constructor for Circle takes one argument, the radius. The constructor for Triangle and Rectangle take 2, base and height.
So in my Singleton Factory class, I have the method:
So to create a Circle radius 8:
So you can see I'm passing an array of parameters in since this is variable( 1 or 2 parameters). This is probably not the best approach, I have thought about subclassing the SingletonFactory to give two classes, one that deals with objects that require 1 parameter passed in, and one that deals with objects that require 2 parameters passed in.
Is this a good idea, or is there a better way to pass in the parameters to the factory to produce specific sized shapes?
But it seems like the client already knows what it wants by the parameters it gathers. Maybe the factory should just have methods for createCircle, createSquare, etc. Yes, you have to add new methods for new shapes, but the client is already going to be going through code changes for new shapes by new sets of parameters ... like Parallelogram and Elipse.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi