473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Forms Inheritance, Incomplete?

KK
** Posting it here cause after couple of days no body responded.**

I was playing around with Windows Forms
and found out this Forms Inheritance feature.

The moment I saw that, I felt this can be
used effectively if the application
contains couople of forms which have
a consistant look and also shares
SOME similar functionality between the forms.

Lets say for example, I have 2 forms and both
forms have buttons as (New, Edit, Save, Close)

Both the forms before showing, should do a
security check(say in forms load event)

In the old vb scenerio, we would create 2 similar
forms seperately and do code cut and paste
for each form which have the similar functions.

But here, with forms inheritance this should
be automaticaly done. But what happense when
u inherit a form at the moment is, it only
sets the controls MODIFIER poperty to
say Protected, Proteted Internal etc..

But If I want to override the parent forms
functionality , say overriding CLOSE buttons
click method, I have to manually edit
the parents click event as;

protected virtual void btnClose_Click(object sender, System.EventArgs e)

and then edit the close button event in the
child form to;

protected override void btnClose_Click(object sender, System.EventArgs e)

And then, in the child forms' event registration for
CLOSE button should be removed/commented(the line below).

//this.btnClose.Click += new System.EventHandler(this.btnNew_Click);

Otherwise, when the child instance get created
it will register 2 events(cause it goes up the
inheritance hierachy and creates parent form instance
first and then come back to child form)
so if u click CLOSE button once,
it will call the close method twise!!!!!

My question is why they didn't automate this couple
of steps ? If a forms controls have been set to
Protected / Protected Internal, they could have
generate the code so that it will really
work.

I want to know what you guys think. May be
I have taken the whole thing from the wrong
end.

May be forms inheritance is there ONLY to get the
UI duplicated? is it?

Regards
KK
Jul 19 '05 #1
2 2160
KK,
** reposting my answer from a couple of days ago! **

KK,
Why go though all that work?

I would use the Template Pattern to introduce a virtual OnClose method to
the base form, that the derived form could override and alter the flow.

The base form's btnClose_Click event handler would call this OnClose method.
The base form's OnClose would have the default behavior (none?) for OnClose,
while the derived form's OnClose would do what was needed.

In Release builds I would consider making OnClose abstract, while in Debug
builds I would make it virtual, as the Forms Designer does not like abstract
base forms. In Debug builds, if the method is meant to be overridden, I
normally make the base.OnClose method simply throw a
NotImplementedException. This way I find out real quick if I forgot to
override the method ;-)
My question is why they didn't automate this couple
of steps ? If a forms controls have been set to
Protected / Protected Internal, they could have
generate the code so that it will really
work. My question would be, why automatic this when the Template Pattern seems to
be a cleaner more OOP solution? :-)

Hope this helps
Jay
"KK" <kk@kk.com> wrote in message
news:uE***************@tk2msftngp13.phx.gbl... ** Posting it here cause after couple of days no body responded.**

I was playing around with Windows Forms
and found out this Forms Inheritance feature.

The moment I saw that, I felt this can be
used effectively if the application
contains couople of forms which have
a consistant look and also shares
SOME similar functionality between the forms.

Lets say for example, I have 2 forms and both
forms have buttons as (New, Edit, Save, Close)

Both the forms before showing, should do a
security check(say in forms load event)

In the old vb scenerio, we would create 2 similar
forms seperately and do code cut and paste
for each form which have the similar functions.

But here, with forms inheritance this should
be automaticaly done. But what happense when
u inherit a form at the moment is, it only
sets the controls MODIFIER poperty to
say Protected, Proteted Internal etc..

But If I want to override the parent forms
functionality , say overriding CLOSE buttons
click method, I have to manually edit
the parents click event as;

protected virtual void btnClose_Click(object sender, System.EventArgs e)

and then edit the close button event in the
child form to;

protected override void btnClose_Click(object sender, System.EventArgs e)

And then, in the child forms' event registration for
CLOSE button should be removed/commented(the line below).

//this.btnClose.Click += new System.EventHandler(this.btnNew_Click);

Otherwise, when the child instance get created
it will register 2 events(cause it goes up the
inheritance hierachy and creates parent form instance
first and then come back to child form)
so if u click CLOSE button once,
it will call the close method twise!!!!!

My question is why they didn't automate this couple
of steps ? If a forms controls have been set to
Protected / Protected Internal, they could have
generate the code so that it will really
work.

I want to know what you guys think. May be
I have taken the whole thing from the wrong
end.

May be forms inheritance is there ONLY to get the
UI duplicated? is it?

Regards
KK

Jul 19 '05 #2
KK
Hi Jay/Martin

Thanks for the explanation. I got ur point Jay :o)
I didnt checked the patterns!!! And If I manage to
find a problem in that i'll ask a question again :ppp

Thanks again!
KK
My question is why they didn't automate this couple
of steps ? If a forms controls have been set to
Protected / Protected Internal, they could have
generate the code so that it will really
work. My question would be, why automatic this when the Template Pattern seems

to be a cleaner more OOP solution? :-)

Hope this helps
Jay

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jinal jhaveri | last post by:
Hi All, I have one question regarding circular inheritance I have 3 files 1) A.py , having module A and some other modules 2) B.py having module B and some other modules 3) C.py having...
37
by: Mike Meng | last post by:
hi all, I'm a newbie Python programmer with a C++ brain inside. I have a lightweight framework in which I design a base class and expect user to extend. In other part of the framework, I heavily...
1
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the...
1
by: Tony Johansson | last post by:
Hello! What does this mean. "The use of inheritance to provide various implementations of a single abstraction tightly binds these implementations to the abstarction. Therfore it, is difficult...
3
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can...
7
by: Hazz | last post by:
Are there any good references/articles/books which provide clarity toward my insecurity still on deciding how to model a complex system? I still feel uncomfortable with my understanding, even...
5
by: jao | last post by:
My company's product uses Postgres 7.4.3. Postgres is working well for us, and we've worked through many performance issues by tweaking the schema, indexes, and posgresql.conf settings. ...
0
by: Tony Johansson | last post by:
Hello! I have a very specific question and that is about how to inherit a visual control for example the control System.Windows.Forms.TextBox without causing the environment to delete the...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.