how to include the same function in 2 different classes

  • Thread starter Thread starter Jeroen Ceuppens
  • Start date Start date
J

Jeroen Ceuppens

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top