nino
nino

Reputation: 29

Converting an uml class diagram to c# code

I have this UML diagram:

enter image description here

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

Answers (1)

Christophe
Christophe

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:

enter image description here

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:

enter image description here

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

Related Questions