What is related to class diagrams

I would like to create a class diagram for my java project. Even if it sounds very simple, I'm a little confused right now.

I am familiar with symbolism, but when do I need to create a connection between two classes?

For example, I have StartClass:

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

Clearly, StartClass is associated with Model , View and Controller . But is Controller now also linked to Model and View ?

Or another example:

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

Does ClassB and ClassA connect to each other?

Sorry for this very simple question ...

+4
source share
4 answers

If your controller looks like this, then it has a connection to Model and View.

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

Or in a more general sense: any class reference stored in a member variable inside the class will be a join in the class diagram.

+3
source

It has been a couple of years since I had to fuss with UML diagrams, but Wikipedia has a good explanation of the usual relationships (association, aggregation, composition, generalization [class inheritance], implementation [interface implementation]).

http://en.wikipedia.org/wiki/Class_diagram#Relationships

In the case of classB.methodB(classA); , I believe that this will be considered a common association, since this is one object that performs an action on / with another (if methodB() does something to save classA in classB ), it should be an aggregation specifically or perhaps even a composition if classB stays on classA for the rest of the program).

+1
source

Here, in the first example, you create different class objects: Model, View and Controller. Since you are saying that the class is associated with Model, View and Controller, as well as the controller is associated with Model and View.

In the second example, both classes: class A and class B have a new connection between themselves.

+1
source

When you get into the MVC pattern, things get a little more complicated, but MSDN has a good explanation on how to model these relationships: http://msdn.microsoft.com/en-us/library/ff649643.aspx

In general, however, when it comes to modeling your application, you should only include classes that are declared as members of another class, and not all that are used in the class in some capacity (you would add a string or int class simply because you use it as a parameter of a method?).

0
source

Source: https://habr.com/ru/post/1489091/


All Articles