Interfaces
-
Hi! Please help me with this. I want to make a program that inherits from two third party classes. (Let's just call it ClassA and ClassB) I know I cannot do multiple inheritance so I need to use interface. But I don't know how. Please help. "To teach is to learn twice"
-
Hi! Please help me with this. I want to make a program that inherits from two third party classes. (Let's just call it ClassA and ClassB) I know I cannot do multiple inheritance so I need to use interface. But I don't know how. Please help. "To teach is to learn twice"
i found this site with excelent tutorials on c# this is chapter 7 , that teach abstract classes & interfaces http://www.programmersheaven.com/2/les\_csharp\_7\_p1
-
i found this site with excelent tutorials on c# this is chapter 7 , that teach abstract classes & interfaces http://www.programmersheaven.com/2/les\_csharp\_7\_p1
-
I have already read that site. It doesn't answer my question. Actually the problem here is that, the classes are THIRD PARTY CLASSES. It already has existing methods that I need to use. Thanks anyway. :) "To teach is to learn twice"
If the methods in the third party classes that you are interested in are public, then you do not need to use any inheritence, multiple or single. Simply use objects of these classes. Otherwise if the methods are protected, then subclass both the third party classes, yourself, and add public methods in the subclasses, that use the protected methods of your interest. Then use your subclasses, instead of the original third party classes. This is kind of a hack. In either case, you can avoid inheriting from those third party classes.
-
Hi! Please help me with this. I want to make a program that inherits from two third party classes. (Let's just call it ClassA and ClassB) I know I cannot do multiple inheritance so I need to use interface. But I don't know how. Please help. "To teach is to learn twice"
Use inheritance for one class and containment for the other:
class C : A // inherit from A
{
private B b; // contain B and add wrapper methodspublic void SomeMethodInB()
{
b.SomeMethod();
}public int SomeOtherMethodInB()
{
return b.SomeOtherMethod();
}...
}Regards, Alvaro