On Sep 27, 2:21 pm, "MikeP" <no_spam@_nospam.comwrote:
>I wrote a replacement for the native .NET class "FileDialog" with my own
"FileOk" event (triggered when the user selects a file and clicks OK).
Let's
say I now want to create a derivative called "MyFileDialog" and replace
the
"FileOk" event with a new event called "MyFileOk". Users of this class
should therefore rely on the latter event and not "FileOk" from the base
class. Is it therefore possible to hide the base class' "FileOk" event so
that users can't invoke it. Redefining it as private doesn't help (the
base
class version kicks in instead) so the only way I can see is to redefine
it
as "public" (using the "new" keyword) and then throwing a
"System.NotImplementedException" (also asserting in the debug version).
This
is ugly IMO however so I'm hoping there's a cleaner way. Any advice would
be
appreciated. Thanks.
If you don't want a client to be able to use a member of the base
class, you shouldn't derive from it.
You could make it virtual, override it, and add a deprecated attribute
to it - but it's a bit horrible. You *should* be able to use an
instance of a derived class as if it were an instance of the base
class.
Thanks for the feedback. Actually I agree with this in principle. However,
this was a very late change so I didn't want to have to start aggregating
the base class as a private member (as one possible solution), especially
for this one minor change. Note that in C++ you have more flexibility with
this issue. You can privately derive from a base class for instance and then
publicly expose only what you want. I find this approach somewhat ugly as
well however. In any case, I'll probably stick with my original idea until
the next release since I control all clients anyway (though I might add the
obsolete attribute you suggested). Anyway, thanks again.