** 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.EventArg s e)
and then edit the close button event in the
child form to;
protected override void btnClose_Click( object sender, System.EventArg s e)
And then, in the child forms' event registration for
CLOSE button should be removed/commented(the line below).
//this.btnClose.C lick += new System.EventHan dler(this.btnNe w_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 2 2185
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
NotImplementedE xception. 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******** *******@tk2msft ngp13.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.EventArg s e)
and then edit the close button event in the child form to;
protected override void btnClose_Click( object sender, System.EventArg s e)
And then, in the child forms' event registration for CLOSE button should be removed/commented(the line below).
//this.btnClose.C lick += new System.EventHan dler(this.btnNe w_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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 module C and some other modules
|
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 use the instance of
this base class (or its children class). How can I ensure the instance
IS-A base class instance, since Python is a fully dynamic...
|
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 application
contains couople of forms which have
a consistant look and also shares
SOME similar functionality between the forms.
|
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 to update the client's code and reuse the abstraction, In
C++, the complete class definition, including the private and protected
sections, is...
|
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 be
used effectively if the application
contains couople of forms which have
a consistant look and also shares
SOME similar functionality between...
| |
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 though I have worked with these
systems on when to decide to use interfaces (and how they should be
developed) as opposed to or complemented by the use...
|
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.
Inheritance would be useful for our application, but we did not use
this feature initially. We're about to revise part of our application,
and this would be...
|
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 control when there are some compile errors.
It's the same problem with any visual control that you inherit. The control
is deleted as soon as you use the...
|
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.
Here is a newbie mistake that I found myself doing (as a newbie), and
that even a master programmer, the guru of this forum, Jon Skeet,
missed!...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| | |