Archittecture

Jedhi

Centurion
Joined
Oct 2, 2003
Messages
127
If you are looking in a design perspective, where you must write a
program in C# that needs to do something else when an event appear (callback). How would you then prefer to make the archittecture ? With Delegates or virtual functions ?
 
A common and recommended design pattern in .NET is to have events raised by On[eventname] functions in the class. These routines should be virtual, so one can hook events externally or actually derive from the class and override. One can also then not call the base method and avoid the overhead of the delegates being called.
 
Thanks !

Do you know any good book about observer pattern, that you could recommand. I does not matter whether it is written in C++ or C#.
 
That link provides about all the information you could possibly need to know, including a link to another article about implementing it in .Net.
 
I have now been reading this book. All along I have been looking into many things and have decided that a baseclass and a container class with some event was the best solution. Until I read this book. Here they recommand to use Observer pattern with delegates and event instead of a base class and an observer interface if you only have single inheritance. Furthermore they write there is no need for Subject, Subjecthelper and observer because the common language runtime makes them obsolete. This means that the subject that is a baseclass goes out !!!!! I do not get it!
 
Back
Top