I have Threads that listens to incoming HTTP messages , i want to enable other developer that use my code to be able to use the messages that i received in any time. I saw in some mobile OS you can implement class and override onRecive function to receive the messages .
is this the right architecture to use in this case? if yes how could i implemented and if its not what is the best way to do it.
Take a look at the Observer Pattern.
You can have an interface called
MessageListener:Users of your library will create their own MessageListeners and will implement the
onMessagemethod which defines what should be done when a message is received. They will also set (or register) this MessageListener with your “threads” before they are started.Now whenever your thread gets a message, it will notify the listener(s) registered with it by calling the
onMessagemethod.