Re: Consuming your own events.
Frans Bouma <[email protected]> Wed, 30 Jan 2008 15:31:15 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <00b301c8634c$c56d2d30$50478790$@nl> |
> 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.
sure it does, but how are you going to avoid that? Even if both
frameworks use methods like Raise<...> it still might be confusing what to do.
However, I think the confusion shouldn't be overexaggerated: class C in one
framework has an On... method, and you use THAT framework's documentation how
to override it. As I said, it's not as if these methods get overriden by
accident, you deliberately put yourself to work on them.
I don't find OnXXX useful for event raising methods if they're virtual
btw. That's combining two things: extensibility when something happens AND
raising an event that something happened. I think that's the issue here and I
agree with you that that's not right. HOW these virtual methods which are
meant to be used for extensibility should be called... I don't think we all
will agree on that, nor do we have to.
> 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.
agreed. Though I think the handlexxx methods can also be called On...
as I don't see On.. methods to be used solely for raising events, there's no
law which dictates that, other than the dark book of winforms... and we all
know how great that framework is...
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 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
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com