By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,435 Members | 2,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,435 IT Pros & Developers. It's quick & easy.

how to include the same function in 2 different classes

P: n/a
Hi, I want to to include the same function in 2 different classes.

class FormView.cs and FormLoad.cs, 2 of Windows.Forms
these 2 classes have a couple of the same methods, what is the best way to
include them simple in both?

Greetz
JC
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You have several choices:

1. You could create a static method and put it in a utility class that these
two forms could access. They could wrap it if required, and even change the
parameters, etc.
2. You could put the method in a base class and have these 2 forms inherit
from that class.
3. You could use aggregation by putting the method in a class, and making
that class a member of your two forms.

In general, prefer containment (choice 3) over inheritance (choice 2) unless
you are fairly sure about what you are doing with inheritance.

HTH,
Mountain

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi, I want to to include the same function in 2 different classes.

class FormView.cs and FormLoad.cs, 2 of Windows.Forms
these 2 classes have a couple of the same methods, what is the best way to
include them simple in both?

Greetz
JC

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.