
derive class from protected class in base class
Hi Kathleen,
Quote:
> Do you mind letting me know why you are doing this? It is an
> issue with the VB compiler. My interest was in regard to a .NET
> infrastucture issue, but would like to be able to pass on real
> world reasons to want to do this (I can imagine some, but what
> were you trying to do?). You can use email if you prefer.
> The unfortunate answer to your question is that you will have to
> use C# to accomplish this in .NET V1.
When you're asking for the issue, I wonder, why I've already provided an
explanation, not to get this question: ;-)
<quote>
Purpose: Somewhere in A, CreateB is called. CreateB is only there to create
a B-object. Classes derived from A can override CreateB and return an object
that is inherited from B. So class C isn't limited to the predefined
B-class.
</quote>
The general explanation in an example:
A
+--reference to--> B
This is the given structure. Now I want to widen the features
of class A. So I write class C that inherits from A. Now the issue: The
B-objects that are created and referenced in A are not powerful enough for
class C. That's the reason for class D: It's inherited from B and contains
improvements or changes and so on. So far, so good. The problem in such a
situation is always: B-objects are created within the base class(!).
Therefore C doesn't have a chance to have references to D-objects
*instead of* B-objects.
When I create an overridable function to create a B-class, successor of
A-classes (here: C) do have the chance to instanciate there own objects that
are derived from D. The A class wouldn't have a problem with these D-objects
because they are derived from B (polymorphism).
I haven't found another way to do something like "inheriting a tree".
Inheriting the root object is no problem but creating further developed
objects that are referenced by the root, isn't that easy. IMHO it can only
be achieved by moving the point of creation to the derived class because the
base class does not even know the D-class.
Of course, I'd be very happy about any other approach.
I hope, this is a better explanation now.
Armin