similar interchangeable type with both singleton and instance objects

S

sakcee

Hi

thanks in advance.

I have a situation in which I need a singleton to which multiple tasks
write.
I implemented it as signlton with bunch of static (yeeha) methods.

specificaly, a singlton logger which allows to log to single file.
(singleLog singlton object)

now i need situation in which each task can have individual singleton
type object to
log to different file.
i.e. a log for each task (logger non-singleton object )

the way I was thinking was to make an interface logProfider with few
functions,
that both singleLog and logger implements and each task has that
interface as member
and I chnage that instance on runtime or someother time i guess

i.e.


class Task(){
logProvider myLog= null

setLogger(logProvide l){
logProvider myLog= l;
}
}

task.setLogger(logger)
task.setLogger(singleLog)



the problem is that this does not work as the singleton has all static
methods while the interface
has instance methods.

how to solve it, or retrofit some design pattern in. with out breaking
all code that is
using singleton's static methods.

specificaly can singletons static methods and another objects instance
method conform to same interface

thanks
 
E

Esmond Pitt

'individual singleton' is a contradiction in terms.

You just need to make up your mind which of these you need. You can't
have both.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top