1

I made a Java application where each class performs a processing and at the end it creates an instance of another class. It also calls a method of this class and passes results to it in the parameters of the method like this:

public class Matrix{
     public double CalculerMinimum()
     {
        ....
           if ((result < min)) {
                        min = result;
               }
       

            Liste lis  = new Liste();
            lis.getFile(min);
         return min;
     }
 }
public class Liste{
     public string getFile(double min)
     {
        ....
           
         return lien;
     }
}

What is the relationship between classes? how I can represent that with a class diagram?

Christophe
  • 68,716
  • 7
  • 72
  • 138
Cissus
  • 37
  • 4
  • Take a look into `interaction diagrams` e.g https://www.tutorialspoint.com/uml/uml_interaction_diagram.htm – Alanpatchi Jun 24 '20 at 17:44
  • Class diagrams show static information. You are talking about behavior. Which of both are you after? – qwerty_so Jun 24 '20 at 18:33
  • @qwerty_so I'm looking for the class diagram, can we represent a dependency relationship between these two classes saying that the List class depends on the Matrix class and we represent this with a discontinuous arrow in class diagram ? – Cissus Jun 24 '20 at 19:37
  • your code is invalid, how can you have `Liste lis = new Liste(); lis.getFile(min);` after `return min;` ? – bruno Jun 24 '20 at 19:39
  • 1
    @bruno Thanks for the comment. I'll change that. – Cissus Jun 24 '20 at 19:42
  • sorry to insist but `Liste lis = new Liste();` is also invalid because *lis* is a *Liste* but `new Liste` return a `List*` probably you just wanted `Liste lis;` ? (if you really want `Liste * lis = new Liste();`so `lis->getFile(min);` please also add `delete lis;` to avoid a memoty leak, but tu allocate in the heap in that case is useless and expensive for nothing) – bruno Jun 24 '20 at 19:48

1 Answers1

3

Your Matrix class creates and uses the Liste class. This is called a dependency. You can represent it in a class-diagram with a dotted arrow and «use» and/or «create».

Your code shows no kind of association nor generalization. The fact that a Liste is used in the implementation of an operation is not sufficient to make an association: this Liste is local and encapsulated in the operation; there is no conceptual association between the two classes themselves (and you could imagine an implementation of CalculerMinimum() that doesn't use any Liste).

What you cannot represent in the class-diagram is the dynamic of the behavior. If you're interested in the dynamics you'd need to use a behavior diagram.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • so we can represent all the class diagram with only dependency relationships – Cissus Jun 24 '20 at 19:43
  • @Cissus Yes, if it's the case there is no problem doing so. – qwerty_so Jun 24 '20 at 19:51
  • @Cissus your may be, but not all in general – bruno Jun 24 '20 at 19:51
  • Indeed. THe fact that a `Liste` is used in the implementation of an operation is not sufficient to make this relation an association: this list is local and encapsulated in the operation. There is no conceptual association between the two classes themselves, and you could imagine an implementation of `CalculerMinimum()` that doesn't use any `liste` – Christophe Jun 24 '20 at 19:51