If a control class uses a method from another class, how do we model the association?

StackOverflow https://stackoverflow.com/questions/23077264

  •  03-07-2023
  •  | 
  •  

Pregunta

If a control class uses a method from another class, how do we model the association?

For example, if I have a User class and a PortalController class that allows users to add or delete another user, how do I model the association in UML?

I suppose User should be a dependency for PortalController since it uses methods from User to create a new user.

User <--- PortalController

But a user would also be the one using the PortalController, so there should be another association:

       uses
User --------> PortalController

Should I draw two arrows?

¿Fue útil?

Solución

If a class A uses a method from another class B, you should model it as a Usage dependency from A to B depicted below enter image description here

Now I am pretty sure that you mix two differents User.

When you said that you PortalController is able to manage a set of User, you are dealing with the structure/implementation of your system so it seems normal to have two classes.

When you said that a User logs to your system, you are dealing with the use case of your system. So in this case the User would be an actor using your system.

Does it help?

Otros consejos

I think you should extract the responsibility of the creation of the user from the user class into another class (e.g. a UserFactory). And as Red Beard already remarked, your design seems to overlay two different concepts of "User".

In that case you would have:

              uses
UserSession --------> PortalController

UserSession --------> User

                    uses
PortalController  --------> UserFactory

PortalController  --------> User

           instantiates
UserFactory --------> User
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top