I have a class AllListener
to encapsulate multiple Listeners as follows.
The problem is I have to write a loop in each event method(onStart()
, onEnd()
).
It's quite normal way in observer pattern code, but it's bad smell. Any better way to write loop once? Thank you!
class AllListener{
List<Listener> listeners;
void onStart(){
for(Listener l:listeners)//loop
l.onStart();
}
void onEnd(){
for(Listener l:listeners)//loop
l.onEnd();
}
}