Form Inheritance

Posted by danielStafford on 18-Nov-2011 10:40

In my application (GUI for .NET, v10.2B04), I have base classes for contact maintenance (contactView.cls, contactModel.cls, contactPresenter.cls). I inherit these class when I create derived classes such as (customerView.cls, customerModel.cls, customerPresenter.cls).

Looking at the customerView InitializeComponent method code I see references to contactView components. If I make more than trivial changes (change properties and placement of UltraGrid controls for example) to contactView, many of its controls properties are not carried forward and the inheritance advantages goes away. I have to recreate the customerView class, doing what it takes to cut and paste its unique attributes / controls.

I do the same for employeeView, manufView, companyView, and vendorView classes / forms. I've had to recreate these several times.

Is this to be expected or am I missing something important (very possible)?

All Replies

Posted by Matt Baker on 19-Nov-2011 21:06

It really depends on the changes you make.  The designer runs a live object, and serializes the live properties of that object.  So every time you make a change, that change needs to be written out to any child class.

Form design (actually any design) benefits a lot from composition instead of inheritance.  Instead of building all the components that are similar across forms into the parent form, try building the common items into user controls instead.  This can help some, but it depends on individual need.

Posted by rbf on 20-Nov-2011 15:07

Have you considered inheriting the Model and Presenter but not the View?

Posted by danielStafford on 21-Nov-2011 07:12

Thanks Matthew and Peter.

The parent contactView form has several tabs with controls on them (UltraGrids, UltraFormattedTextEditors, etc).  This last modification was big. Originally, I was trying to be creative with the UltraTilePanel, putting grids on each of 4 panels thinking a user would like them with their animated movements and such. The feedback in beta was mixed and I removed them and placed the controls on a tab[0] UltraPanel . This is where I ran into trouble. The mods were to big, and some of the grids attributes were not carried over to the child forms.

I will give composition a lead role in my next development effort, be it this application or another one.

Several times I've nearly given up on form inheritance, but small tweaks are the rule now, and I'm sticking with it.

This thread is closed