Interfacing with Pre-Existing Classes

NeuralJack

Centurion
Joined
Jul 28, 2005
Messages
138
Hi what is the mechanism for which I could use to add functions to lists of certain classes? I'm guessing that there is one.

So I want these lists to have some of the same functions:
List (of Class1)
List (of Class2)
List (of Class3)

The specific functions I'd want to add are like:
.GetObjectFromName
.GetIndexFromName

So Each of Class1, Class2, and Class3 have a variable named "Name"

I know about how to use interfaces but I'm not sure about how add an interface with a pre-existing class or collection object.

Thanks
 
Last edited:
Just to clarify a couple of things...

Firstly each of the classes expose the same methods (or a least some of the methods are the same) that need to be moved to an interface - correct?

Secondly you would like to be able to create a generic List object that could contain any of these objects - also correct?

If so you would just need to define a new interface that contains the relevant methods and get each of your existing classes to implement this interface. This will probably require a little bit of editing in VB to make sure each of the existing methods is followed by the relevant Implements statement as well...

Generics can be restricted to classes that implement a particular Interface as explained by marble_eater in this post
 
Back
Top