If it's
abstract
, you can't use it the way you're doiing it. You MUST derive a new class from it, like so:
public class MyComponent : Component
{
}
Then you can do this :
public class MyComponentCollection : List<MyComponent>
{
}
MyComponentCollection myComponents = new MyComponentCollection();
myComponents.Add(...);
or this:
List<MyComponent> myComponents = new List<MyComponent>;
myComponents.Add(...);
I prefer the first usage example because it's cleaner on the codemonkey side.
EDIT (after comment) =======================
In order to create a collection of
Component
-based objects, the collection must contain objects that are derived from an object derived from component (because it's abstract). My suggestion is to either create an interface, or change
Component
to not be abstract. You could also consider changing the
addChild
method to accept an
Object
instead of a
Component
. Then, you wouldn't need to make
Component
abstract.