Alternative to 'abstract' in base forms?

D

Dave Veeneman

I'm creating several forms that inherit from a base form. I want to require
the derived forms to implement certain methods of the base form. The easy
solution would be to declare abstract methods in the base form. But I can't
do that, since the WinForms Designer can't instantiate an abstract form.

So, what would be a good alternative to using abstract methods. I'm thinking
about declaring an interface, but that seems kind of klunky. Thanks.
 
M

Mattias Sjögren

Dave,
I'm creating several forms that inherit from a base form. I want to require
the derived forms to implement certain methods of the base form. The easy
solution would be to declare abstract methods in the base form. But I can't
do that, since the WinForms Designer can't instantiate an abstract form.

What I've done in the past is something like this

#if !DEBUG
abstract
#endif
class MyBaseForm : Form
{
#if DEBUG
public virtual void Foo() { throw new NotImplementedException(); }
#else
public abstract void Foo();
#endif
...
}

and then make sure I have DEBUG defined whenever I need to use the
forms designer.



Mattias
 

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