473,463 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Method assignment

Can I assign a method of a class to a method of another class?

I have a method called ChangeEmployee(int aNewEmployee),
I want to assign this method to another class's method so that the other
class's method to do the same thing.
Jul 17 '06 #1
5 1206
Alan T wrote:
Can I assign a method of a class to a method of another class?

I have a method called ChangeEmployee(int aNewEmployee),
I want to assign this method to another class's method so that the other
class's method to do the same thing.
Hi Alan,

If your classes can be related by inheritance, then one class can inherit
the other:

public class TheBaseClass
{
public void ChangeEmployee ( int aNewEmployee )
{
...
}
}

public class TheDerivedClass : TheBaseClass
{
...
}

Now, you can access ChangeEmployee from an instance of TheDerivedClass, and
indeed any other derived classes of TheBaseClass.

There are a few other methods of minimising code redundancy, but if it's
appropriate to use inheritance, then I suggest taking that approach first.

--
Hope this helps,
Tom Spink

Google first, ask later.
Jul 17 '06 #2
Hi,

The two classes are not related to each other.
I have embedded one member(listview) of a class inside the other class.

"Tom Spink" <ts****@gmail.comwrote in message
news:eF*************@TK2MSFTNGP05.phx.gbl...
Alan T wrote:
>Can I assign a method of a class to a method of another class?

I have a method called ChangeEmployee(int aNewEmployee),
I want to assign this method to another class's method so that the other
class's method to do the same thing.

Hi Alan,

If your classes can be related by inheritance, then one class can inherit
the other:

public class TheBaseClass
{
public void ChangeEmployee ( int aNewEmployee )
{
...
}
}

public class TheDerivedClass : TheBaseClass
{
...
}

Now, you can access ChangeEmployee from an instance of TheDerivedClass,
and
indeed any other derived classes of TheBaseClass.

There are a few other methods of minimising code redundancy, but if it's
appropriate to use inheritance, then I suggest taking that approach first.

--
Hope this helps,
Tom Spink

Google first, ask later.

Jul 17 '06 #3
pr
Hi
If the method is public you can access that method anywhere. or else it
should be static
regs

Jul 17 '06 #4
What will be the syntax of method assignment ?

"pr" <pr********@masconit.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hi
If the method is public you can access that method anywhere. or else it
should be static
regs

Jul 17 '06 #5
Alan T wrote:
Hi,

The two classes are not related to each other.
I have embedded one member(listview) of a class inside the other class.

"Tom Spink" <ts****@gmail.comwrote in message
news:eF*************@TK2MSFTNGP05.phx.gbl...
>Alan T wrote:
>>Can I assign a method of a class to a method of another class?

I have a method called ChangeEmployee(int aNewEmployee),
I want to assign this method to another class's method so that the other
class's method to do the same thing.

Hi Alan,

If your classes can be related by inheritance, then one class can inherit
the other:

public class TheBaseClass
{
public void ChangeEmployee ( int aNewEmployee )
{
...
}
}

public class TheDerivedClass : TheBaseClass
{
...
}

Now, you can access ChangeEmployee from an instance of TheDerivedClass,
and
indeed any other derived classes of TheBaseClass.

There are a few other methods of minimising code redundancy, but if it's
appropriate to use inheritance, then I suggest taking that approach
first.

--
Hope this helps,
Tom Spink

Google first, ask later.
Hi Alan,

It's hard to give an appropriate answer without more information about what
it is you need to replicate in the methods. If both methods can perform
the same operation, without requiring an instance of the class, then you
can embed your code in a static method, which you can then call from
anywhere:

///
public static void MyMethod ( )
{
...
}
///

Can you post a code example?

--
Hope this helps,
Tom Spink

Google first, ask later.
Jul 17 '06 #6

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

Similar topics

7
by: Andy Fish | last post by:
Hi, I'm trying to figure out how to invoke a method on an object given the object and the method name. For example, here's a simple object with a method: function MyObj (pName, pDesc) {...
5
by: Olumide | last post by:
I need to swap the onclick method bound to a layer (nLayer). The assignment, document.getElementById('nLayer').onclick = nullScript; // OK works when the method bound (i.e. nullScript)...
5
by: jmd | last post by:
hello. i am trying VC++ 7.1 (with vsnet 2003). my example : class Complex { public: Complex ( float re_ = 0.0, float im_ = 0.0 ) : re(re_), im(im_) {} float Re () { return ( re ); } float...
1
by: Mike | last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in...
44
by: gregory.petrosyan | last post by:
Hello everybody! I have little problem: class A: def __init__(self, n): self.data = n def f(self, x = ????) print x All I want is to make self.data the default argument for self.f(). (I
3
by: John Machin | last post by:
I have stumbled across some class definitions which include all/most method names in a __slots__ "declaration". A cut-down and disguised example appears at the end of this posting. Never mind...
3
by: AWasilenko | last post by:
I'm still in the process of learning python via a handful of books I bought. One book I am reading just introduced Base Class Methods. I found that I needed more understanding on this concept and...
6
by: Soneji | last post by:
This is a pretty specific problem, so I'm not posting the whole program. ( but I can if you really need it ) I have a good understanding of what's wrong, I just can't figure out how to combat it. ...
15
by: Sunburned Surveyor | last post by:
I'm a Java developer in the process of writing a class library in C#, so please bear with me. I'm trying to write a method that can return a generic Object OR a Decimal value. In Java I would...
11
by: markryde | last post by:
Hello, Followed here is a simplified code example of something which I try to implement; in essence , I want to assign a value to a return value of a method is C. I know, of course, that in this...
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
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.