Reputation: 29
I have this UML diagram:
I have tried to convert it to C# code:
internal class Task:Organizer
{
public string Name { get; }
public string Description { get; set; }
public int Priority { get; set; }
private bool done=false;
public bool Done
{
get { return done; }
set { done = value;}
}
Is this how it's supposed to look like?
Upvotes: 1
Views: 746
Reputation: 73376
No, this is not supposed to look like this: Task:Organizer
is inheritance in C#. In UML it would be represented as follows:
This would be obviously wrong, because your diagram does not express inheritance but shared aggregation.
Bu the way, your input diagram seems not correct. It uses an association with the shared aggregation symbol (white diamond) on the wrong side. The corrected version would look like:
But since the aggregation does not add any semantic, the rest of my answer is valid also for the incorrect input diagram. The diagram could as well use a simple association without diamond and have exactly the same implementation.
To implement this, you need to create two classes, Organizer
and Task
with a collection of Task
as property of Organizer
.
class Task
{
...
}
class Organizer
{
...
public List<Task> Tasks { get; }
...
}
Upvotes: 2