I have a Contract class. The contract is valid 1 Jan 2010 - 31 Dec 2010.
It can be in state Active or Passive, depending on whic开发者_运维技巧h date I ask the instance for it's state. ex. if I ask 4 July 2010, it's in state Active, but if I ask 1 Jan 2011, it's in state Passive.
Instances are created using constructor dependency injection, i.e. they are either Active or Passive already when created, null is not allowed as a parameter for the internal state member.
One initial/created vertex is drawn in a UML state machine diagram. I have two arrows, leading out from the initial vertex, one leading to state Active and the other to state Passive.
Is this a correct representation of dependency injection in UML ?
The question specifically concerns statemachine diagrams where the first state after the initial state/vertex, is decided outside the boundaries of the diagram.
The Jude/Ashtah tool allows these kinds of constructs, i.e. drawing multiple lines from the inital vertex of the diagram, which leads me to beleive that it is correct UML graphical syntax.
This is related to How model statemachine, when state is dependent on a function? which initiated the question on how to model DI in general, in UML.
you can solve the states part as I suggested in your other question and the DI can be shown using the dependency in class diagram.
I would say not. The question to ask though is: Does the class state machine/behaviour differ between Active and Passive versions of your class?
If yes then use two separate state machine diagrams under your class object, one for Passive and one for Active.
An activity diagram can be used to show that a choice is made (by use of a join) prior to class creation.
If the two instances behave the same and so pass through the same states then just place a label on the Initial to first state transition to show this and maybe an entry procedure within the first state to show it.
Dependency injection is just an implementation detail (even if it is quite important). So on the question of how to model dependency injection in UML you can model DI either as an association, aggregation or composition, depending on what you want to express with those classes.
精彩评论