Abstract classes and visual inheritance

You know what sucks? In .NET IDEs, including Visual Studio and SharpDevelop, the IDE needs to create an instance of a class to edit it in the form designer. The upshot of this is that you can't have both an abstract base class and visual inheritance.

By way of overview, the situation is basically this: I have a bunch of VB.NET data entry/update forms that are essentially all the same. They edit different database tables and so have different fields, but the underlying data access code is almost exactly the same. So, being an object-oriented kind of person, I figured I'd create a generic data entry form and inherit from that. That saves me having to do a copy-and-paste job for all the boiler-plate ADO.NET code.

Since this class only exists for other classes to inherit from it, it only makes sense mark it as abstract. Since VB.NET doesn't support multiple inheritance, if I want the derived classes to inherit from Windows.Forms.Form (which I do), then my abstract class has to inherit from it. But that breaks the forms designer because you can't create an instance of an abstract class.

The solution? Well, don't make the class abstract. Just keep it as a regular class and don't ever instantiate it in code. It's not "pure" object-oriented solution, but as far as I can tell, it's the only one that works.

You can reply to this entry by leaving a comment below. This entry accepts Pingbacks from other blogs. You can follow comments on this entry by subscribing to the RSS feed.

Add your comments #

A comment body is required. No HTML code allowed. URLs starting with http:// or ftp:// will be automatically converted to hyperlinks.