Re: MustInherit in Window forms

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tom Dacon (tdacon_at_community.nospam)
Date: 07/22/04


Date: Thu, 22 Jul 2004 11:32:27 -0700

Oops...

... so you can choose to code a generic DisconnectFromAbrServer() method
there, and it'll be run if the SUBCLASS implementor chooses not to implement
a custom version of the method. ...

Sorry 'bout that.

Tom Dacon
Dacon Software Consulting

"Tom Dacon" <tdacon@community.nospam> wrote in message
news:OlCdImAcEHA.2388@TK2MSFTNGP11.phx.gbl...
> The essence of a MustInherit form is that it's an abstract form: it can't
> itself be instantiated. Think of an abstract Automobile class, marked
> MustInherit, with subclasses such as Ford Explorer, Mazda Miata, etc. You
> can't just walk into an automobile dealership and buy an Automobile. You
> have to buy an instance of an instantiable subclass such as a Ford
Explorer.
> An abstract class can be thought of as a template or a design pattern,
sort
> of, and is most useful as a mechanism for polymorphism: that is, you can
> downcast any instance of a subclass to the base class and invoke one of a
> known list of members that are available for all subclasses of the base
> class, while actually running the code that was written for the subclass
> (although for completeness' sake I must note that you can force the base
> class's method be be invoked, if you choose).
>
> Consequently, much depends on whether your base class is usable itself:
that
> is, do you want applications to be able to just create and use an instance
> of the base class as a 'concrete class', or must they subclass it with
> custom logic in all cases?
>
> If you don't want your base class to be instantiated, mark it MustInherit.
> Even in a MustInherit class, you can supply default implementations of
> properties and methods, so you can choose to code a generic
> DisconnectFromAbrServer() method there, and it'll be run if the base class
> implementor chooses not to implement a custom version of the method. You
can
> force it to be run in all cases, or you can allow it to be overridden in
the
> subclass through the overridable keyword.
>
> If you are OK with having your base class instantiated, you don't mark it
> MustInherit. If a generic implementation of DisconnectFromAbrServer()
method
> will suffice for all subclasses if no other is available, you can
implement
> it in the base class. If you are OK with subclasses supplying their own
> implementation, mark the method Overridable. If you REQUIRE that they
> implement their own (i.e., a generic implemenation cannot be used), mark
the
> method MustOverride and don't supply any code in the base class.
>
> And document, document, document...
>
> This whole inheritance business, what with new, shadows, overrides,
> overridable, mustoverride, mustinherit, etc., is pretty complex. I'd
suggest
> taking the time to write a testcase that exercises the various
combinations
> so that you can study the nuances. I've done this for myself in C#, but
> haven't yet taken the time to do the same for VB, otherwise I'd post the
> testcase.
>
> HTH,
> Tom Dacon
> Dacon Software Consulting
>
>
> "Niklas" <Niklas@discussions.microsoft.com> wrote in message
> news:7DF800BC-EDD9-470E-BA70-643888034AE7@microsoft.com...
> > Hi
> > I have made a base class and to be sure that developers do not forget to
> implement DisconnectFromAbrServer I have done the following:
> >
> > Friend MustInherit Class frmBaseAbrForm
> > Inherits System.Windows.Forms.Form
> > Implements IAbrServerEnabled
> > ...
> > Friend MustOverride Sub DisconnectFromAbrServer() Implements
> IAbrServerEnabled.DisconnectFromAbrServer
> >
> > In the derived class:
> >
> > Friend Class frmNewTocc
> > Inherits frmBaseAbrForm
> > ...
> > Friend Overrides Sub DisconnectFromAbrServer()
> > 'TODO: Add code.
> > End Sub
> >
> > The problem is that the VS designer can not create an instance of
> frmBaseAbrForm because it is declared as abstract and an exception is
thrown
> in design time. What can I do? Is it not posible to create Forms as
> MustInherit?
> >
> > Regards
> > /Niklas
>
>
>



Relevant Pages

  • Re: MustInherit in Window forms
    ... "Tom Dacon" wrote: ... and it'll be run if the SUBCLASS implementor chooses not to implement ... >> If you don't want your base class to be instantiated, ... >> implementor chooses not to implement a custom version of the method. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: using dict for data attributes instead of self
    ... >So why does he wants a dictionary-like base class if he never uses any ... (IMO that __setitem__ subclass override trick is not a good substitute ... BTW, the above was probably written before you could subclass the builtin dict, but now ... A subclass could use lists as additional ways to store info if needed. ...
    (comp.lang.python)
  • Re: Lahman, how ya doing?
    ... >> variety of classes if they were all derived from a single base class ... I regard that as one of C++'s deficiencies because too many ... >people abuse it to navigate from superclass to subclass during routine ... >collaboration because there is only one instance in hand to navigate. ...
    (comp.object)
  • Re: Convenience constructors and non-final setters
    ... any subclass has no choice than use ... functionality, the base class might be better off as an interface. ... ColoredCartPoint and ColoredPolarPoint concrete subclasses that implement ...
    (comp.lang.java.programmer)
  • Re: Lahman, how ya doing?
    ... A major reason was the that performance and low-level machine control were primary design objective. ... didn't take me long to realize that a generic pointer can only hold any variety of classes if they were all derived from a single base class, but you can't invoke methods unique to a derived class with a pointer to the base class. ... I regard that as one of C++'s deficiencies because too many people abuse it to navigate from superclass to subclass during routine collaborations. ...
    (comp.object)