Lets say I create an abstract class that manages some network functionality for me.
I want to be able to be notified when something changes. For example: OnConnect
or OnDisconnect
.
Should I create events for those kinds of functions or implement them as abstract methods?
public event OnConnectDelegate OnConnected;
or:
protected abstract OnConnected(SomeClientObject connectedClient);
I prototyped both solutions and both work as expected. But how do I know in general if I should expose functionality as an event or as an abstract method? Are there any situations where I should clearly prefer one over the other? Events support multiple receivers but one also has to remove them when the receiver doesn't need to receive them anymore.