Reputation: 6413
If I have a class A that has some functions and I wrote a new class called B which aim is to test the functions that class A provide and I need to detect the relationship between the tow classes, is it ok to say that the relationship between A and B is a dependency ?
thanks in advance
Upvotes: 0
Views: 627
Reputation: 6175
With respect to your diagram, if B tests A, then the arrow should point from A to B. As xmojmr's page (see note to Tom Kilian's answer) mentions, there are some problems with the spec.
Just which class depends on which is semantically ambiguous in the spec. The spec is clear on this: there is a client and a supplier. The arrow end is supplier, and the tail end is client. The problem is with the example diagram in Superstructure 2.4.1, fig. 7:
xmojmr's link says this:
This example in fact shows opposite to what UML specification states. CarFactory depends on the Car class. Car class could be defined without the knowledge of CarFactory class, but CarFactory requires Car for its definition because it produces Cars.
While I agree with the assessment that this example shows the opposite of the specification, I disagree with explanation of why. Which has knowledge of which is irrelevant here; that's the concern of an association arrow, not a dependency arrow. The dependency arrow points at the class that is supplying functionality to the class that's doing the pointing (so to speak).
Therefore, the problem is that there's an error in the diagram, not the description. The Car class does indeed have a dependency on the CarFactory class, meaning the arrow is on the wrong end. CarFactory is a supplier of instantiation operations to the Car class. Car class is a client of CarFactory, using its instantiation operations. Therefore, the arrow should point to CarFactory, not Car.
xmojmr's link also says this, and I agree:
It is also wrong to say that "... the Car class is an instance of the CarFactory class." The Car class is instantiated by the CarFactory class.
Upvotes: 0
Reputation: 36333
Absolutely. B depends on A in a way that it will test A's capabilities. You might use stereotypes (e.g. here <<test>>
) to pinpoint specific characterizations of connectors. Though you should not overuse stereotypes.
Dependencies are the weakest under the UML connectors. An association is somewhat stronger (e.g. it expresses in classes that one has an instance of the other inside). There are lengthy discussions out there when to use which connector. A dependency is always good. It shows that there is a conceptual relation. An association shows a somewhat stronger relation then.
Upvotes: 3