D
Daniel Billingsley
My application will have various forms for editing my business objects. All
the objects to be edited on the various forms will either derive from a
common class or implement a common interface. Let's just say it's an
interface for sake of this discussion.
There is a lot of common functionality between the forms, of course. Using
forms inheritance seemed like a great way to reuse that common code.
Of course there are some parts of the common code that need to interact with
the interface, but the actual business object appropriate for the particular
derived form will of course be instantiated by the derived form. The
controls specific to editing that type of business object will of course be
on the derived form.
So, it seemed logical to create some abstract methods and properties in the
base form. That means the class itself must be abstract. Not so fast - the
designer complains it needs to instantiate the base class and can't because
it's abstract.
Hmmm..
That leaves me with two options that I can see. I'm just wondering which is
considered a better practice, or if there's a third I haven't thought of.
1) Declare protected fields (of the interface Type) in the base form which
could be set directly in the derived form in all the appropriate places.
2) Declare the needed methods and properties as virtual in the base class.
In the base class each simply throws a NotSupportedException since only the
override in the derived form should actually be used.
the objects to be edited on the various forms will either derive from a
common class or implement a common interface. Let's just say it's an
interface for sake of this discussion.
There is a lot of common functionality between the forms, of course. Using
forms inheritance seemed like a great way to reuse that common code.
Of course there are some parts of the common code that need to interact with
the interface, but the actual business object appropriate for the particular
derived form will of course be instantiated by the derived form. The
controls specific to editing that type of business object will of course be
on the derived form.
So, it seemed logical to create some abstract methods and properties in the
base form. That means the class itself must be abstract. Not so fast - the
designer complains it needs to instantiate the base class and can't because
it's abstract.
Hmmm..
That leaves me with two options that I can see. I'm just wondering which is
considered a better practice, or if there's a third I haven't thought of.
1) Declare protected fields (of the interface Type) in the base form which
could be set directly in the derived form in all the appropriate places.
2) Declare the needed methods and properties as virtual in the base class.
In the base class each simply throws a NotSupportedException since only the
override in the derived form should actually be used.