c# - Using a singleton to send messages between any two classes -
is using singleton send messages between classes or bad idea?
one side of communication registers listener (listening string or object, perchance parameters) , other side sends messages. there can multiple or no listeners message.
using such pattern means objects in different projects can communicate without having reference 1 another.
a case useful sending errors in application 1 object. can send error part of application , error manager can hear errors have occurred.
what downsides taking such approach?
problems come mind globals create hard testing , possibility of unexpected consequences since in app listening event , in unrelated projects.
for situations similar using observer pattern , making event dispatcher singleton.
c# events design-patterns singleton global-variables
No comments:
Post a Comment