0

I did some reading on the <<instantiate>> relationship in UML class diagrams. It's a dependency relationship where one side depends on the other.

However, I'm not sure who depends on who: does the instantiating class depend on the instantiated class, or is it the other way around? I found contradicting answers to this.

Let's call the instantiating class ClassA and the instantiated class ClassB.

On one hand, ClassA must have a new ClassB() statement in it's code. Which means it has to 'know about' ClassB - a classic example when explaining what dependency is. So that means ClassA (the instantiating class) depends on ClassB.

However logically the existence of instances of ClassB might depend on an operation done by ClassA.

Which is correct: the instantiating class is said to depend on the instantiated class (meaning the dashed arrow will be pointing from the instantiating class to the instantiated class), or the instantiated class is said to depend on the instantiating class (so the arrow will be pointing the opposite direction)?

Aviv Cohn
  • 21,190
  • 31
  • 118
  • 178

1 Answers1

2

I believe your confusion stems from the contradiction between the example and the language of the UML 2.4.1 specification, where it states the following for "instantiate",

In the example below, the Car class has a dependency on the CarFactory class. In this case, the dependency is an instantiate dependency, where the Car class is an instance of the CarFactory class.

[ CarFactory ] -- <<instantiate>> ---> [ Car ]

Figure 7.38 - An example of an instantiate dependency

This is an old quirk in the specification but it hasn't been fixed thus far. The text obviously contradicts the figure and common sense, the Car can be instantiated on its own, and it's the CarFactory factory class that depends on the existence of the Car class and not vice versa.


Which is correct: the instantiating class is said to depend on the instantiated class (meaning the dashed arrow will be pointing from the instantiating class to the instantiated class), ...

Notice the arrow direction,

A dependency is shown as a dashed arrow between two model elements. The model element at the tail of the arrow (the client) depends on the model element at the arrowhead (the supplier). [UML 2.4.1 7.3.12]

So the ("yes") answer to your quoted question above is that the instantiating class depends on the instantiated class.

mockinterface
  • 921
  • 4
  • 5
  • 2
    I would say that the arrow direction *is* intuitive. I don't see anything counter-intuitive in having the class at the tail of the arrow depend on the class at the head of the arrow. – Bart van Ingen Schenau Apr 27 '14 at 13:03
  • @BartvanIngenSchenau Agree it is rather a subjective observation, I've removed the offending part - thanks for pointing that out. – mockinterface Apr 28 '14 at 10:18