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
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