Re: Consuming your own events.
Sebastien Lambla <[email protected]> Wed, 30 Jan 2008 13:24:51 +0000
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <[email protected]> |
What happens when you use two libraries, one using OnXxx as event handling virtual methods, one using it as event raising virtual methods? When you mix the two in the same project it becomes very confusing, documentation or not. I can't think of any generic test that could differentiate between forgetting to call the base OnXxx method and the one that does it on purpose. Compare that to Cancel = true, non virtual RaiseXxx and protected virtual HandleXxx... Compiler-checked and testable. -- SerialSeb http://serialseb.blogspot.com > -----Original Message----- > From: Discussion of development on the .NET platform using any managed > language [mailto:[email protected]] On Behalf Of Frans > Bouma > Sent: 30 January 2008 13:06 > To: [email protected] > Subject: Re: [DOTNET-CLR] Consuming your own events. > > > Most developers have to use multiple frameworks in their day-to-day > jobs. > > > > The fact that multiple frameworks use the OnXxx naming convention > > differently introduces consistency issues that directly impact the > > robustness of your code, especially when you build frameworks for > others. > > Sure, but that's unavoidable: there are always guidelines which > are > contradicting, so which one to follow? earlier today I showed that the > Webforms' DataSourceControl uses different methods than winforms for > the same > thing, which one to follow? > > The best and only thing you can do is: > 1) be consistent inside your own framework > 2) document things properly. > > > When something smells badly, you can try and take the point of view > that one > > of the implementation choices is the right one, apply it, and expect > > developers to understand and accept your view of the pattern, or you > can > > avoid it like the plague and define better semantics to solve the > problem > > once and for all. > > Then still you run the risk of it being > misunderstood/misinterpreted. > The one true thing you need is proper documentation: if it's properly > described what to do and what the methods stand for, there's no > confusion and > no problem. > > Sure if people refuse to read documentation or are too stupid > to write > the documentation, then things are out of control. Darwin.... > > FB > > > > -- > > SerialSeb > > http://serialseb.blogspot.com > > > > > > > -----Original Message----- > > > From: Discussion of development on the .NET platform using any > managed > > > language [mailto:[email protected]] On Behalf Of > Sébastien > > > Lorion > > > Sent: 30 January 2008 12:41 > > > To: [email protected] > > > Subject: Re: [DOTNET-CLR] Consuming your own events. > > > > > > Well, I understand your scenario better now, but ... this is (up to > > > now) specific to WPF and it is not the first time that the one > making > > > guidelines is breaking them .... *cough* binding *cough*. > > > > > > Why would this apply to, say, ObservableCollection<T> ? > > > > > > Sébastien > > > > > > On 1/30/08, Sebastien Lambla <[email protected]> wrote: > > > > I'm talking about using attached events that your type is not an > > > owner of. > > > > For example > > > > > > > > public event MouseButtonEventHandler MouseDown > > > > { > > > > add > > > > { > > > > this.AddHandler(Mouse.MouseDownEvent, value, false); > > > > } > > > > remove > > > > { > > > > this.RemoveHandler(Mouse.MouseDownEvent, value); > > > > } > > > > } > > > > > > > > > > > > Now let's see what the OnMouseDown method is. > > > > > > > > protected virtual void OnMouseDown(MouseButtonEventArgs e) > > > > { > > > > } > > > > > > > > Sparing you with the nasty details: > > > > EventManager.RegisterClassHandler(typeof(UIElement), > > > Mouse.MouseDownEvent, > > > > new MouseButtonEventHandler(UIElement.OnMouseDownThunk), true); > > > > > > > > > > > > So the next generation UI framework uses OnXxx for event handling > > > (not > > > > raising!). Raising itself uses the RaiseEvent method. > > > > > > > > This conflicts with the guidelines that have been discussed, > conflict > > > less > > > > with the ones i've just explained. Because of that, I advise > against > > > using > > > > the On notation, to prevent the confusion introduced by different > > > > frameworks... > > > > > > > > -- > > > > SerialSeb > > > > http://serialseb.blogspot.com > > > > > > > > > > > > > -----Original Message----- > > > > > From: Discussion of development on the .NET platform using any > > > managed > > > > > language [mailto:[email protected]] On Behalf Of > > > Sébastien > > > > > Lorion > > > > > Sent: 30 January 2008 11:45 > > > > > To: [email protected] > > > > > Subject: Re: [DOTNET-CLR] Consuming your own events. > > > > > > > > > > On 1/30/08, Sebastien Lambla <[email protected]> wrote: > > > > > > > > > > > > When you start, like in WPF, using different property stores > for > > > your > > > > > > events, the problem becomes even worse (and it's that problem > > > that > > > > > has > > > > > > triggered my move to this new pattern). > > > > > > > > > > > > > > > Could you elaborate on this bit, I am not sure I follow you. I > > > think > > > > > you mean to use a hashtable to associate events to their > delegate > > > > > instead of default > > > > > storage (ie one field by event) ? If so, how is it affected by > the > > > > > OnXXX pattern ? > > > > > > > > > > =================================== > > > > > This list is hosted by DevelopMentor(R) http://www.develop.com > > > > > > > > > > View archives and manage your subscription(s) at > > > > > http://discuss.develop.com > > > > > > > > =================================== > > > > This list is hosted by DevelopMentor(R) http://www.develop.com > > > > > > > > View archives and manage your subscription(s) at > > > http://discuss.develop.com > > > > > > > > > > > > > -- > > > Sébastien > > > www.sebastienlorion.com > > > > > > =================================== > > > This list is hosted by DevelopMentor® http://www.develop.com > > > > > > View archives and manage your subscription(s) at > > > http://discuss.develop.com > > > > =================================== > > This list is hosted by DevelopMentor® http://www.develop.com > > > > View archives and manage your subscription(s) at > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentor® http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com