F
Flomo Togba Kwele
I am having trouble with the following design. I want an object containing a Parent object and a
List of its Child objects. The Child object is abstract, so the List must contain concrete objects
derived from it.
When I instantiate the ParentChild object and add Child-derived objects to the List, I will be able
to add any object derived from Child. However, I want the List to contain only a single type
derived from Child, and I want methods using children to behave polymorphically.
I don't think this snippet will work. Can anyone suggest an alternative?
Thanks, Flomo
namespace Test {
class ParentChild {
private Parent parent;
private Child<T> children;
}
class Parent {}
abstract class Child {}
class ChildTypeA: Child {}
class ChildTypeB: Child{}
}
--
List of its Child objects. The Child object is abstract, so the List must contain concrete objects
derived from it.
When I instantiate the ParentChild object and add Child-derived objects to the List, I will be able
to add any object derived from Child. However, I want the List to contain only a single type
derived from Child, and I want methods using children to behave polymorphically.
I don't think this snippet will work. Can anyone suggest an alternative?
Thanks, Flomo
namespace Test {
class ParentChild {
private Parent parent;
private Child<T> children;
}
class Parent {}
abstract class Child {}
class ChildTypeA: Child {}
class ChildTypeB: Child{}
}
--