I’m designing a framework for managing certain api calls and other long-running tasks on our mobile clients. I will be designing and implementing it on a basic java program which then can be passed onto the client developers to extend the classes in the framework and implement their concrete classes where they do context-specific stuff.
There is a place where the manager would send notifications to the components that are waiting on a task. Now in the AbstractManager I have a method called registerClient(Messenger m) where a client can register itself as a listener so they can know when a task is finished.
Now if I want to keep it abstract, I can’t say that it’s a Messenger object, each app and platform might use a different implementation of notification. How can I design this so that registerClient can be implemented in any way?
You could provide a an interface (e.g.
IMessenger) that each messenger object is required to implement and make that the type of the parameterIf you chose the right methods for the interface (mostly the same as you have for
Messengernow), you can provide multiple implementations of the interface that you can use in theregisterClient()method