Thread View: borland.public.csharpbuilder.oodesign
11 messages
11 total messages
Started by David Clegg
Wed, 20 Oct 2004 00:38
Extending events in inherited forms
Author: David Clegg
Date: Wed, 20 Oct 2004 00:38
Date: Wed, 20 Oct 2004 00:38
39 lines
2720 bytes
2720 bytes
I've got a C# base form which contains a third party Win XP style navigation bar. The base form provides some common functionality via this control, and descendant forms may expand on this. In the Delphi Win32 world, I'd normally achieve this by having a virtual method called in the controls relevant event, which descendants could then override with gay abandon. Providing they're good little citizens, and call the inherited method, everything is quite spiffy. I originally started going down this route with my C# implementation, but it dawned on me that the same can be achieved by taking advantage of the .NET Frameworks multi-cast delegate support. This way all the descendant form has to do is to assign the same event handler and both would be called, giving the same result. However, this latter approach seems less clean to me, and may be harder to maintain by someone less familiar with the code. If you provide a virtual method you're quite clearly signaling your intentions that this method was intended to be extended upon in descendant classes. OTOH, it only takes one naughty implementor to not call the inherited method and intended functionality is broken. What are other's thoughts on this? -- Cheers, David Clegg dclegg_at_ebetonline_dot_com Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :-) Now supports Google Groups searching with Dyna-extend(tm) technology! QualityCentral. The best way to bug Borland about bugs. http://qc.borland.com "Oh, yeah, what are you gonna do? Release the dogs? Or the bees? Or the dogs with bees in their mouth and when they bark, they shoot bees at you?" - Homer Simpson
Re: Extending events in inherited forms
Author: Jim Cooper
Date: Wed, 20 Oct 2004 13:57
Date: Wed, 20 Oct 2004 13:57
34 lines
2349 bytes
2349 bytes
> This way all the descendant form has to do is to assign the same > event handler and both would be called, giving the same result. I'm not sure the result would necessarily be the same, since you cannot guarantee the order in which the different handlers get called. With inherited calls (or base.XXX, which seems uglier syntax, to me) you can. > However, this latter approach seems less clean to me, and may be harder > to maintain by someone less familiar with the code. If you provide a > virtual method you're quite clearly signaling your intentions that this > method was intended to be extended upon in descendant classes. I agree. This is the more easily maintained option, IMO. > OTOH, it only takes one naughty implementor to not call the inherited > method and intended functionality is broken. Sure, but that's always a problem with virtual methods. I've even had occasions when it was correct to call inherited in some descendants and not in others :-) You can only comment/document it and hope for the best. And of course, your unit tests will immediately pinpoint any problems, won't they? ;-) Cheers, Jim Cooper _______________________________________________ Jim Cooper jim@falafelsoft.com Falafel Software http://www.falafelsoft.co.uk _______________________________________________
Re: Extending events in inherited forms
Author: David Clegg
Date: Wed, 20 Oct 2004 22:39
Date: Wed, 20 Oct 2004 22:39
31 lines
1993 bytes
1993 bytes
Jim Cooper wrote: > I'm not sure the result would necessarily be the same, since you > cannot guarantee the order in which the different handlers get > called. With inherited calls (or base.XXX, which seems uglier syntax, > to me) you can. Very good point, although in this particular instance the order didn't really matter. > And of course, your unit tests will immediately pinpoint any problems, > won't they? ;-) <blush> At least I'm using an OPF this time round. I thought a switch to TDD as well would be a bit too much to digest. :-) -- Cheers, David Clegg dclegg_at_ebetonline_dot_com Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :-) Now supports Google Groups searching with Dyna-extend(tm) technology! QualityCentral. The best way to bug Borland about bugs. http://qc.borland.com "Are you sure this is the Sci-Fi Convention? It's full of nerds!" - Homer Simpson
Re: Extending events in inherited forms
Author: Marc Rohloff TeamB
Date: Thu, 21 Oct 2004 01:51
Date: Thu, 21 Oct 2004 01:51
17 lines
1651 bytes
1651 bytes
On 20 Oct 2004 15:39:33 -0700, David Clegg wrote: > Very good point, although in this particular instance the order didn't > really matter. As far as I know the order is very reliable. Someone could get the delegate list and call them in random order but I have yet to see this done (besides since you are calling the delegate you are in control) The way I have done this is to have a non-overridable method which you always want done and have it call a virtual method which in the base class does nothing so even if inherited is never called your code still runs. -- Marc Rohloff [TeamB] marc rohloff at myrealbox dot com
Re: Extending events in inherited forms
Author: David Clegg
Date: Thu, 21 Oct 2004 02:10
Date: Thu, 21 Oct 2004 02:10
22 lines
1922 bytes
1922 bytes
Marc Rohloff [TeamB] wrote: > The way I have done this is to have a non-overridable method which you > always want done and have it call a virtual method which in the base > class does nothing so even if inherited is never called your code > still runs. That's a good idea. I think I'll do that too. -- Cheers, David Clegg dclegg_at_ebetonline_dot_com Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :-) Now supports Google Groups searching with Dyna-extend(tm) technology! QualityCentral. The best way to bug Borland about bugs. http://qc.borland.com "This donut has purple in the middle. Purple is a fruit!" - Homer Simpson
Re: Extending events in inherited forms
Author: Marc Rohloff TeamB
Date: Thu, 21 Oct 2004 02:35
Date: Thu, 21 Oct 2004 02:35
10 lines
1299 bytes
1299 bytes
On 20 Oct 2004 19:10:52 -0700, David Clegg wrote: > That's a good idea. I think I'll do that too. Sure implement every idea posted here and your app is sure to work much better <g> -- Marc Rohloff [TeamB] marc rohloff at myrealbox dot com
Re: Extending events in inherited forms
Author: David Clegg
Date: Thu, 21 Oct 2004 02:38
Date: Thu, 21 Oct 2004 02:38
20 lines
1797 bytes
1797 bytes
Marc Rohloff [TeamB] wrote: > Sure implement every idea posted here and your app is sure to work > much better <g> Why do you think I come here? It certainly isn't for the food. <g> -- Cheers, David Clegg dclegg_at_ebetonline_dot_com Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :-) Now supports Google Groups searching with Dyna-extend(tm) technology! QualityCentral. The best way to bug Borland about bugs. http://qc.borland.com "Vampires are make believe, just like elves and gremlins and eskimos." - Homer Simpson
Re: Extending events in inherited forms
Author: Joanna Carter (TeamB)
Date: Thu, 21 Oct 2004 08:25
Date: Thu, 21 Oct 2004 08:25
15 lines
1495 bytes
1495 bytes
"David Clegg" <dclegg@gmail.com> a οΏ½crit dans le message de news: xn0dos1v49evp000f@newsgroups.borland.com... > Why do you think I come here? It certainly isn't for the food. <g> Food? Where, where ? :-) Joanna -- Joanna Carter (TeamB) Consultant Software Engineer TeamBUG support for UK-BUG TeamMM support for ModelMaker
Re: Extending events in inherited forms
Author: David Clegg
Date: Fri, 22 Oct 2004 00:45
Date: Fri, 22 Oct 2004 00:45
20 lines
1958 bytes
1958 bytes
Joanna Carter (TeamB) wrote: > Food? Where, where ? :-) There was, but you're too late to the party. Don't worry, it wasn't that nice anyway. :-) -- Cheers, David Clegg dclegg_at_ebetonline_dot_com Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :-) Now supports Google Groups searching with Dyna-extend(tm) technology! QualityCentral. The best way to bug Borland about bugs. http://qc.borland.com "Being eaten by a crocodile is just like falling asleep, in a blender." - Homer Simpson
Re: Extending events in inherited forms
Author: Jim Cooper
Date: Fri, 22 Oct 2004 17:20
Date: Fri, 22 Oct 2004 17:20
15 lines
1564 bytes
1564 bytes
> As far as I know the order is very reliable. The call order is undefined, according to everything I've ever seen and heard. While it may always be the same order at the moment, you shouldn't rely on it remaining that way, apparently. Cheers, Jim Cooper _______________________________________________ Jim Cooper jim@falafelsoft.com Falafel Software http://www.falafelsoft.co.uk _______________________________________________
Re: Extending events in inherited forms
Author: Marc Rohloff TeamB
Date: Fri, 22 Oct 2004 18:33
Date: Fri, 22 Oct 2004 18:33
12 lines
1448 bytes
1448 bytes
On Fri, 22 Oct 2004 18:20:30 +0100, Jim Cooper wrote: > The call order is undefined, according to everything I've ever seen and > heard. While it may always be the same order at the moment, you > shouldn't rely on it remaining that way, apparently. You can get the complete list of delegates and call them any way you want if you want to be paranoid. -- Marc Rohloff [TeamB] marc rohloff at myrealbox dot com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads