dimanche 28 août 2016

Single responsibility principle of a class when processing a queue in a thread

I am using a library which provides me a callback everytime a message is received. But within this callback I cannot publish a message to whoever the object that sent the message. So what I've done is I created another class "ReceivedMessageHandler" and created a Queue in that class. Then from the callback method I call the insertToQueue method of ReceivedMessageHandler and process the messages there. Now there is a ScheduledExecutor in the ReceivedMessageHandler class that processes the queue. So according to single responsibility of a class, is what I've done correct or should I create another class which has the Queue object and has getters setters for it. Then process the items in that queue in the ReceivedMessageHandler. Is that how it should be done or is what I've done correct? Any advice would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire