Search code examples
javaclass-diagram

What is connected in class diagrams


I would like to create a class diagram for my java project. Even if this sounds very simple, I am just a bit confused now.

I am familiar with the symbolic but when do I have to create a connection between two classes?

For example I have a StartClass:

Model model = new Model();
View view = new View();
Controller controller = new Controller(view, model);

It is clear that StartClass is connected with Model, View and Controller. But is Controller now also connected with Model and View?

Or another example:

ClassA classA = new ClassA();
ClassB classB = new ClassB();

classB.methodB(classA);

Does ClassB and ClassA have now a connection between each other?

Sorry for this really simple question...


Solution

  • If your Controller looks like the following, then it has a connection to Model and View.

    class Controller {
       public Controller(View view, Model model) {
           this.view = view;
           this.model = model;
       }
    }
    

    Or more generally: any class reference saved in a member variable inside a class will be a connection in a class diagram.