I
iksrazal
I have a singleton that works well. I have serveral classes that uses
this singleton to preform many operations. I want to break up these
many operations into methods for each class. My idea is:
class useSingleton1
{
private static MySingleton _instance = MySingleton.getInstance();
public void doWork()
{
doTask1();
doTask2();
}
public void doTask1()
{
// setup task1
// ...
_instance.doSomething1();
}
public void doTask2()
{
// setup task2
// ...
_instance.doSomething2();
}
}
This would be repeated in useSingleton2, etc. One potential caveat:
The singleton does Thread work, but that is working fine as it is now
- doing:
class useSingletonAsIsNow1
{
public void doWork()
{
MySingleton _instance = MySingleton.getInstance();
// setup task1
// ...
_instance.doSomething1();
// setup task1
// ...
_instance.doSomething2();
}
}
I'm currently just repeating for useSingletonAsIsNow2, etc, but as I
said I'd like to break up the code into methods.
I could do:
doTask1(_instance);
doTask2(_instance);
but it seems ugly to me.
Any ideas on the best approach?
iksrazal
this singleton to preform many operations. I want to break up these
many operations into methods for each class. My idea is:
class useSingleton1
{
private static MySingleton _instance = MySingleton.getInstance();
public void doWork()
{
doTask1();
doTask2();
}
public void doTask1()
{
// setup task1
// ...
_instance.doSomething1();
}
public void doTask2()
{
// setup task2
// ...
_instance.doSomething2();
}
}
This would be repeated in useSingleton2, etc. One potential caveat:
The singleton does Thread work, but that is working fine as it is now
- doing:
class useSingletonAsIsNow1
{
public void doWork()
{
MySingleton _instance = MySingleton.getInstance();
// setup task1
// ...
_instance.doSomething1();
// setup task1
// ...
_instance.doSomething2();
}
}
I'm currently just repeating for useSingletonAsIsNow2, etc, but as I
said I'd like to break up the code into methods.
I could do:
doTask1(_instance);
doTask2(_instance);
but it seems ugly to me.
Any ideas on the best approach?
iksrazal