An output needs to provide a way to:
- add a new subscriber
- unsubscribe a current subscriber
- notify subscribers
- make its state known
- be updated when a change occurs
In the programming world, this is not a new problem. There is a time-honored solution to this called the "observer pattern." The pattern describes Subjects and Observers which correlate exactly to our Outputs and Inputs. This problem is so common that in .NET they built in a way to do most of this work for you: .NET, "Events" will give you all of this. Since we're doing this in C# anyway, I'm opting for events. Events have added benefits which we may also take advantage of later.CODE: http://downloads.softhardsoft.com/2009-03-25.zip
0 comments:
Post a Comment