Abstract Base form - can I fake it?

R

Rachel Suddeth

I have a base form (Windows.Forms) that really should be abstract. There are
certain methods that must be overridden. However, if I make it abstract, I
can
not get designer support. (VS tells me " The designer must create an
instance of type
'Bloodhound.MaintBase' but it cannot because the type is declared as
abstract." )

Is there any way I can force these method to get overridden but still get
designer
support?

Failing that (as I suspect will happen), anyone have a good suggestion for
how to
make very sure that it will be immediately obvious on first run of the
program if
the programmer forgets to implement any of the methods that must be
overridden?

One is called in the constructor (to get data objects of a derived type
which are
implemented as base type objects in the base form), and the others are
called
from button click or other such events (to make server calls which must
use the
derived type data objects.) Right now, some of these might not be noticed
until some fairly thorough testing is done...

Any suggestion appreciated...
Thanks,
Rachel
______________________________________________________________

Roydan Enterprises Ltd
602 North 9th Street
Manitowoc, WI 54220-3924

1-800-236-6906
(920)-684-3688
Fax: (920)-684-3630
 
R

Robby

You could create an interface and have your forms implement it. All the
poperties, methods and events of an interface must be implement. You could
even manage your forms as objects of the interface instead of form objects
for the parts of the program that expects those functions are available.
This will give you early binding on the interface. You also would get
design time Visual Studio support.

Robby
 
B

Bruce Wood

The solution I've seen most often used is to make the methods and
properties in the base class throw NotImplementedException if they're
ever called outside of DesignMode (don't forget to test this.DesignMode
and don't throw an exception if the Designer is trying to instantiate
your form!).
This defers the checking to runtime, but at least there's checking.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top