Reputation:
I have class Controller
in my java project, which has method like this:
As you can see, in the first line I am getting Singleton instance of ActualModes
class and call method getActualModes()
.
So the first question is, which relatinship I should use in class diagram.
After that I am creating new instane of ModeContext
class and then call method executeStrategy
. In this case, which relatiship is better ?
Upvotes: 0
Views: 812
Reputation: 36295
It should be like this:
Access to the singleton (note the stereotype which is just convenient and no obligation or general standard) is anonymous and so you just have a dependency. The ModeContext
in contrast uses a private (I don't know the scoping rules of the language you used, so I made it pivate) property called context
. Note the dot which is saying exactly that.
Upvotes: 1
Reputation: 6089
Disclaimer: UML does not specify a mapping between Java and UML, so every answer to your question is open for debate.
I think both relationships are dependencies, drawn as dashed arrows from Controller
to ActualModes
and from Controller
to ModeContext
. The definition of 'dependency' according to the UML 2.5 specification (§7.8.4.1) is:
A Dependency is a Relationship that signifies that a single model Element or a set of model Elements requires other model Elements for their specification or implementation.
An example of a type of relationship which is in my opinion less suited, is the association, although its definition (§11.5) is quite broad:
An Association classifies a set of tuples representing links between typed instances. (...) An Association specifies a semantic relationship that can occur between typed instances.
One could argue that there are links between Controller
and the other two classes, in the form of variables, but these variables are local method variables, which exist only temporarily during the execution of the method. Associations represent more durable links, e.g. class members - as far as I understand UML and as far as I have seen associations used in practice.
Upvotes: 0