Sometimes I want a simple generic Listener without defining my own class. Is there a predefined “something happened and here is a string or object or whatever” in Java or Android?
Sometimes I want a simple generic Listener without defining my own class. Is there
Share
A project I’ve worked on had that. It lead to some frightfully unreadable and unmaintainable code once a class implemented the “MyListener” interface to handle two completely different kind of events. There was a lack of separation of concerns, and you had no idea when or how that method might be invoked.
This isn’t the kind of code duplication you need to avoid. Just because two methods/interfaces share the same basic signature doesn’t mean they should be combined into one. I suggest you create listener interfaces that are completely self-documenting with regards to when and how they are used.