views:

203

answers:

3

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 which 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 http://stackoverflow.com/questions/2779922/how-model-statemachine-when-state-is-dependent-on-a-function which initiated the question on how to model DI in general, in UML.

A: 

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.

ChrisBD
Good idea to complement with activity diagram showing the choice.This is what feels intuitive to me:http://imagebin.ca/view/6SN7pN.htmlHow would this change with the label idea that you're proposing ?
A: 

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.

ablaeul
Any example of the translation from statemachine diagram (SMD), to classes implemented using DI ? I'm hoping for to see the whole chain, from UML SMD diagram to implementation, in one small example.
+1  A: 

Hi, 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.

Gabriel Ščerbák
"you can add the call to that function in a constructor, so your contract is in proper state right away"Yes, this is what I want to achieve, BUT there can be multiple proper states (in the example either Active or Passive), and I don't know UML well enough to be able to express it in correct UML notation.
As you responded, using multiple initial vertexes is invalid UML notation, so that's not an option. Part of what I'm trying to find out, is if multiple arrows leading out of the initial vertex is valid UML ?
@hjo1620 it is not, but you can use the choice element to have multiple arrows go from that element.
Gabriel Ščerbák