mercredi 29 avril 2015

Design patterns: exposing notifications using a protocol

I have got several types of a logic controller class that handle the communication with a remote resource. To do so each class uses an instance of a network controller class that deals with the connection details: connects to a resource, sends data, receives data. The logic controller classes are notified of data changes from the network controller class using notifications. So in my current solution each logic controller class registers for the notifications and implements specific functions to deal with them differently.

However, if I want to do proper code engineering, I wonder whether it would be more robust to use protocols and delegation.

I wonder if I could define which methods the logical controller classes need to implement in order to receive the notification. However I am not sure if this makes sense and is correct because I do not want inheritance here.

Any suggestion?

Aucun commentaire:

Enregistrer un commentaire