Code Design - Including listeners/events in contract
Assume there is a module A such that module B and C depend on it. Module A
support listener pattern i.e. modules like B and C can listen to events
generated by A. Therefore module A is decoupled from its listeners. Now we
want to have some set of contracts (interface in Java) that can
collectively define the contract of module A.
The problem is to insert listeners into the contract. Should I add
functions like "public addListener(Listener listener)" into the contract?
Other way is to use abstract class that implements listener part and leave
other functions as abstract. I really do not want to extend classes since
at some point if we decide to implement two contract in a single class
then it is impossible. Can you discuss the above cases and any insight
into related topic is appreciated.
Why I want listeners in contract? This is because modules that listen to A
should not break up if someday someone re-writes module A. If this is not
a good idea then let me know.
No comments:
Post a Comment