MVC representation in UML class diagram

Asked

Viewed 1,360 times

4

I’m building the class diagram of my project and I got a question at a certain point. In the project I create an instance of my Controller class in main and pass the reference (I know that in Java the passage is always by value, but when we pass the object we are passing a copy of the reference, so in general lines it ends up giving in the same, in most cases) this Controller instance for three Menus that are part of my project’s View.

public class Principal {

    public static void main(String[] args) {
        MeuController controller = new MeuController();
        MenuProdutos menuProdutos = new MenuProdutos(controller);
        MenuComprador menuComprador = new MenuComprador(controller);
        MenuCompras menuCompras = new MenuCompras(controller);
        //resto do código
   }
}

From there I call several methods of these menus to perform registrations, sales purchases and etc. My question is: how to represent this in a class diagram? I cannot use a composition between my Main class (which contains the main) and the controller, as there is no controller attribute, although there is an instance of it in the main.
Also, I’m not sure what the relationship would be between my main class and the classes MenuProdutos, MenuComprador and MenuCompras.
Also not sure what the relationship between the Menu classes and the controller would be, I thought it might be a composition, since I have controller-like attributes in each of them.

1 answer

2

To represent the relationship between Main and Controller and Menu classes, you can use a dashed arrow with the instant stereotype.

inserir a descrição da imagem aqui

You can find more details about dependency usage in this link: http://www.uml-diagrams.org/dependency.html

The relation between Menu and Controller will be an aggregation. Because the Controller is independent of the Menu. inserir a descrição da imagem aqui

The composition would be used if the Controller object existed only upon the existence of the Menu object. If so, the Controller would not be being passed as a parameter to the Menu. In such cases, usually when the Menu is destroyed, the Controller will be destroyed together.

You can find more details about composition and aggregation at this link: http://imasters.com.br/artigo/18901/uml/uml-composicao-x-agregacao?trace=1519021197&source=single

Browser other questions tagged

You are not signed in. Login or sign up in order to post.