473,387 Members | 3,801 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,387 software developers and data experts.

How to use delegation?

Hi,
I'm using two form classes and I would like all methods of the second class
(the child class) to be managed by the first class (the main class).
Is delegation the best solution for me?
If so, how can I define delegation?
--
Thanks,

Mayer
Jul 18 '07 #1
5 1437
If you inherit child from main you will get all main methods automatically
in child, if I got your question right.

Why do you mention delegation? Do you have some specific example in mind
which made you consider delegation?
"Mayer" <me*********@dds-security.com.donotspamwrote in message
news:E2**********************************@microsof t.com...
Hi,
I'm using two form classes and I would like all methods of the second
class
(the child class) to be managed by the first class (the main class).
Is delegation the best solution for me?
If so, how can I define delegation?
--
Thanks,

Mayer


Jul 18 '07 #2
Mayer wrote:
I'm using two form classes and I would like all methods of the second class
(the child class) to be managed by the first class (the main class).
Is delegation the best solution for me?
No. Inheritance would be the way to go.

Have Second inherit from First and both will do exactly the same thing
until you start overriding and changing Second.
If so, how can I define delegation?
Delegate methods (known in other languages as Function Pointers) are a
way for you to call a method at run-time without knowing anything about
it at compile time, other than it has a given signature.

Event handlers are all delegates under the covers - the Control that
raises the event (and calls your Event Handler [delegate] method) knows
nothing whatever about your class and yet it can still call your method!

HTH,
Phill W.
Jul 19 '07 #3
Hi Alex,
Thank you for your answer.
My case is as follows:
The main form, opens the child form, nothing to do with inheritance.
I odn't want to dispose the inner class, the child. It means, instead of
calling childForm.fillColor, I prefer to activate mainForm.FillColor which
activates the inner private fillColor.

Is delegate the best solution?

--
Thanks,

Mayer
"AlexS" wrote:
If you inherit child from main you will get all main methods automatically
in child, if I got your question right.

Why do you mention delegation? Do you have some specific example in mind
which made you consider delegation?
"Mayer" <me*********@dds-security.com.donotspamwrote in message
news:E2**********************************@microsof t.com...
Hi,
I'm using two form classes and I would like all methods of the second
class
(the child class) to be managed by the first class (the main class).
Is delegation the best solution for me?
If so, how can I define delegation?
--
Thanks,

Mayer


Jul 19 '07 #4
I believe that depends how you define "best"

If that's one property you can just call child property from code handling
change of main form property. No need for delegation.

If you want to implement this functionality for all properties of child
form, you need to look into reflection (see PropertyInfo.SetValue at
http://msdn2.microsoft.com/en-us/lib...ue(VS.71).aspx)

Again, I don't see the need for delegation. You can add method to child,
which could be called with property name and new value.

However, even in this case I would consider inheritance and put property
change handling method into base class (for child), in case you might need
different children with same behavior.

Does this answer your question?

"Mayer" <me*********@dds-security.com.donotspamwrote in message
news:22**********************************@microsof t.com...
Hi Alex,
Thank you for your answer.
My case is as follows:
The main form, opens the child form, nothing to do with inheritance.
I odn't want to dispose the inner class, the child. It means, instead of
calling childForm.fillColor, I prefer to activate mainForm.FillColor which
activates the inner private fillColor.

Is delegate the best solution?

--
Thanks,

Mayer
"AlexS" wrote:
>If you inherit child from main you will get all main methods
automatically
in child, if I got your question right.

Why do you mention delegation? Do you have some specific example in mind
which made you consider delegation?
"Mayer" <me*********@dds-security.com.donotspamwrote in message
news:E2**********************************@microso ft.com...
Hi,
I'm using two form classes and I would like all methods of the second
class
(the child class) to be managed by the first class (the main class).
Is delegation the best solution for me?
If so, how can I define delegation?
--
Thanks,

Mayer




Jul 19 '07 #5
Yes, thank you very much.
--
Mayer
"AlexS" wrote:
I believe that depends how you define "best"

If that's one property you can just call child property from code handling
change of main form property. No need for delegation.

If you want to implement this functionality for all properties of child
form, you need to look into reflection (see PropertyInfo.SetValue at
http://msdn2.microsoft.com/en-us/lib...ue(VS.71).aspx)

Again, I don't see the need for delegation. You can add method to child,
which could be called with property name and new value.

However, even in this case I would consider inheritance and put property
change handling method into base class (for child), in case you might need
different children with same behavior.

Does this answer your question?

"Mayer" <me*********@dds-security.com.donotspamwrote in message
news:22**********************************@microsof t.com...
Hi Alex,
Thank you for your answer.
My case is as follows:
The main form, opens the child form, nothing to do with inheritance.
I odn't want to dispose the inner class, the child. It means, instead of
calling childForm.fillColor, I prefer to activate mainForm.FillColor which
activates the inner private fillColor.

Is delegate the best solution?

--
Thanks,

Mayer
"AlexS" wrote:
If you inherit child from main you will get all main methods
automatically
in child, if I got your question right.

Why do you mention delegation? Do you have some specific example in mind
which made you consider delegation?
"Mayer" <me*********@dds-security.com.donotspamwrote in message
news:E2**********************************@microsof t.com...
Hi,
I'm using two form classes and I would like all methods of the second
class
(the child class) to be managed by the first class (the main class).
Is delegation the best solution for me?
If so, how can I define delegation?
--
Thanks,

Mayer




Jul 23 '07 #6

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

Similar topics

7
by: Rene Pijlman | last post by:
Section 6.5 "What is delegation?" of the FAQ says: "Python programmers can easily implement delegation. For example, the following class implements a class that behaves like a file but converts...
3
by: Jacob | last post by:
Hello All, I am trying to serve out some content via IIS that is hosted on a remote fileserver, and am unable to get the delegation working correctly. Our setup is as follows: Local LAN...
6
by: DPfan | last post by:
Is the following so-called "delegation"? If not how to make some changes so that the F class delegates its operation to an E instance. On the other hand the following code runs without any...
3
by: Tony Johansson | last post by:
Hello! What does it mean with delegation and can you give me one example. //Tony
2
by: | last post by:
Hi, I am working on a n-tier app using remoting. I am using the VS 2005 beta 2. My server needs to access a remote resources on behalf on the connected user. I have configured my server like :...
2
by: russell.lane | last post by:
I'm building out a pretty standard n-tier web application. The stack includes application/presentation, biz logic, and data access layers on top of an SQL server back end. We want to use...
4
by: JimLad | last post by:
In advance, sorry if this is the wrong group... SQL Server 2000 SP3 on Server 2003. SQL Account and Computer both Trusted for Delegation. Given SPN. IIS 5.0 on W2000. Kerberos enabled....
6
by: Marc Castrechini | last post by:
This is a classic double hop delegation issue, however its the first time we are setting this up so we are doing something incorrectly. If we run through the IDE or using a localhost path on the...
3
by: Patrick | last post by:
Hello I have the following scenario - SQL 2005 server (serversql) - Windows 2003 with IIS (serveriis) - Windows 2003 ADS (serverads) I want to connect to an intranet application using NTML...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.