Inherit without exposing?
-
Hi Maybe I need to dig up my old varsity handbooks "Coding 101" but posting is easier :-O I want to inherit an class-A (cause I want to use it's methods in a class-B), but I don't want it's methods exposed past class-B. I.e. Dim o as ClassB, if I type "o." it should only list class-B methods. Is there a way to do this, maybe it is not called inheritance? (PS: Using VB.NET 2.0) Francois Happy Coding!
-
Hi Maybe I need to dig up my old varsity handbooks "Coding 101" but posting is easier :-O I want to inherit an class-A (cause I want to use it's methods in a class-B), but I don't want it's methods exposed past class-B. I.e. Dim o as ClassB, if I type "o." it should only list class-B methods. Is there a way to do this, maybe it is not called inheritance? (PS: Using VB.NET 2.0) Francois Happy Coding!
instead of inehritance, you can use delegation (or aggregation), i.e. Class B will contain a reference to an instance of a class A object and delegate it to do the requested work. This way B will expos no A methods. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
instead of inehritance, you can use delegation (or aggregation), i.e. Class B will contain a reference to an instance of a class A object and delegate it to do the requested work. This way B will expos no A methods. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
If I understand you correctly you're saying "Dim o as new class-A" and then use "o.methodA" in class-B. I did think of this - but was wondering if there was another ("cleaner") way to skin the cat? :confused:
-
If I understand you correctly you're saying "Dim o as new class-A" and then use "o.methodA" in class-B. I did think of this - but was wondering if there was another ("cleaner") way to skin the cat? :confused:
This is clean. Object aggregation it's often a good design alternative to complex class hierachies. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Hi Maybe I need to dig up my old varsity handbooks "Coding 101" but posting is easier :-O I want to inherit an class-A (cause I want to use it's methods in a class-B), but I don't want it's methods exposed past class-B. I.e. Dim o as ClassB, if I type "o." it should only list class-B methods. Is there a way to do this, maybe it is not called inheritance? (PS: Using VB.NET 2.0) Francois Happy Coding!
-
Then what about
private
inheritance in C++? This does exactly what the OP is after.Steve
-
Then what about
private
inheritance in C++? This does exactly what the OP is after.Steve
-
What I'm saying is that in C++
private
inheritance doesn’t really model an is-a relationship (not to the users of the class; internally to the class it does) but is inheritance nevertheless. e.g.class CMyClass : private CMyBase
{
// Stuff...
};Steve
-
What I'm saying is that in C++
private
inheritance doesn’t really model an is-a relationship (not to the users of the class; internally to the class it does) but is inheritance nevertheless. e.g.class CMyClass : private CMyBase
{
// Stuff...
};Steve