473,386 Members | 1,846 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,386 software developers and data experts.

how to include the same function in 2 different classes

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
1 1603
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: danarz | last post by:
If you invoke the "check_link" function using the "Go" link than everything works as I expect. If invoking it using the Submit button than the text field value shows the new value ("Executed...
3
by: Mungo Jerrie | last post by:
Hi there :-) I have some problems with the same instance of my xmldocument across 3 different classes. See code below: class one { protected static XmlDocument doc = new XmlDocument(); ...
4
by: MikeAth via DotNetMonster.com | last post by:
Hi all, I have two different classes and one instance of the Form. I would like to access the members of the Form instance in both classes without having to create a new instance in the other...
10
by: Peter | last post by:
Hi, how can I do this (I don't really want to do this but what I do want the same function name but have different return types and the compiler keeps saying "public function .... they differ only...
1
by: Rico Rivera | last post by:
I have two files: FileA.vb FileB.vb FileA.vb contains the following sample code: NameSpace SomeNamespace Public Class SomeClassA Public Shared Function MethodA() As String
7
by: Ron | last post by:
Hello, I have 4 classes that use 4 DTS packages on 4 different tables. So I have Dim cls1 As New clsDTS1, cls2 As New clsDTS2 Dim cls3 As New clsDTS3, cls4 As New clsDTS4 Each class has a...
4
by: tshad | last post by:
I have a function that I want to jump to from 2 different controls (ImageButton and LinkButton). The problem is I get the error: Method 'Public Sub PrintPage_Click(sender As Object, e As...
3
by: catphive.lists | last post by:
I have a bunch of function object classes of the form struct MyFunc : unary_function<arg,ret> { MyFunc(arg) : state(arg) {} void operator() (arg) { /*code here*/ } }; in various cpp files....
1
by: PengYu.UT | last post by:
Hi, Are there any walkaround to enable functions in the derived class with the same function name but different return type? In the following example, D1 and D2 are B's derived class. I want...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.