Re: MustInherit in Window forms
From: Tom Dacon (tdacon_at_community.nospam)
Date: 07/22/04
- Next message: Jeff Johnson [MVP: VB]: "Re: Check Email"
- Previous message: Krakatioison: "Re: Text problem"
- In reply to: Tom Dacon: "Re: MustInherit in Window forms"
- Next in thread: Niklas: "Re: MustInherit in Window forms"
- Reply: Niklas: "Re: MustInherit in Window forms"
- Messages sorted by: [ date ] [ thread ]
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
>
>
>
- Next message: Jeff Johnson [MVP: VB]: "Re: Check Email"
- Previous message: Krakatioison: "Re: Text problem"
- In reply to: Tom Dacon: "Re: MustInherit in Window forms"
- Next in thread: Niklas: "Re: MustInherit in Window forms"
- Reply: Niklas: "Re: MustInherit in Window forms"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|