1

I have problem with dependencies in class diagram. I use these classes

class data and class algorithm

What is the relationship between classes? Thank you for your help

Data.cs =>

public class Data {

     public string Data1 { get; set; }
     public string Data2 { get; set; }


     public Data(string data1, string data2)
     {
         this.Data1 = data1;
         this.Data2 = data2;
     }

     public string data1data2()
     {
         return Data1 + " " + Data2;
     }
 }

Algorithm.cs =>

public static class Algorithm
{

  public static void MethodData()
  {
     List<Data> data = new List<data>();

     data.Add(new Data("aaaa", "bbb"));
     .
     .
     foreach(Data item in data)
     {
        Console.WriteLine(item.data1data2());
     }
     .  
   }         
}
peter.novan
  • 73
  • 1
  • 2
  • 8

1 Answers1

1

Algorithm has a one to many relationship to Data. This can be seen by the presence of a field that holds a list (many) of data. One Algorithm knows about many data objects.

Data does not have any relationship to algorithm, because it does not have any fields of type Algorithm. Generally one would therefore draw the relationship with an arrow from Algorithm pointing at the Data object.

This may be helpful: Direction of the association arrow in UML class diagrams

Community
  • 1
  • 1
Gus
  • 6,719
  • 6
  • 37
  • 58
  • Thanks for the help, but how to call this relationship? Association? Aggregation?Dependency? – peter.novan Apr 18 '13 at 21:02
  • Dependency is easy, if a class can't live (i.e. compile or run) without another class then it has a dependency on the other class. So Algorithm has a dependency on Data, but Data has no dependency on Algorithm. The question of Association/Aggregation cannot be answered by looking at the code alone. That distinction is about how the the designer thingks about the relationship. An Order aggregates LineItems pretty clearly, whereas an Person is probably only associated with his/her Vehicle(s). The question would be is the Algorithm a container for the Data or just something that knows about it? – Gus Apr 19 '13 at 00:32