TDC
TDC

Reputation: 1929

C# List of Different Data Types

I am writing an application to track tasks, a bit like project planning software. I have an Entity base class and 2 classes which inherit from Entity:

  1. Task
  2. Activity

The Task class is rich in the task details, start date, finish date, description etc. The Activity class is simply a container for Task or Activity objects, most of its properties are simply aggregates of its children.

I want to be able to create hierarchies of tasks which means that the children of an Activity must be of data type Task or Activity.

Should I use List<Entity> collection for the children of an Activity or is there a better approach please?

Upvotes: 1

Views: 220

Answers (1)

Michał Turczyn
Michał Turczyn

Reputation: 37357

That is correct approach, that's what polimorhpism is for :) You can also consider having two lists: one of activities and one of tasks, to have better distinction.

Upvotes: 1

Related Questions