How does a UML dependency translate into code?

Hello,

Suppose I have two classes A and B with the following class diagram:

|A|- - - - - ->|B|

According to what I understand, it means that B is either a local variable of A or a parameter of one of A's methods. Can B be an instance variable of A or would it change the relation to Association?

Balteo.

[346 byte] By [balteoa] at [2007-9-28 2:31:55]
# 1

An association, with no other information, can be represented in many ways.

- A instance varable.

- A collection as an instance variable (containing the object.)

- Another class which has references to both of the classes.

- Used as a local variable in a single method and discarded when the method is done.

jschella at 2007-7-7 22:04:34 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

A dependency doesn't necessarily translate directly into code. A dependency only express that one thing depends on another thing. You should also be absolutely clear whether the dependency is among two classifiers or two objects.

I think dependencies are most useful in the analysis model for expressing how classes or packages use each other, meaning that they in fact are implicitly given by underlying call graphs and class hierarchies.

Søren Bak

soren_baka at 2007-7-7 22:04:34 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

jschell and soren are both correct. There is only another thing I shall add - in dependencies there is a supplier consumer relation. So, the consumer is dependent on the supplier, in ways which need not be an association (at least directly, however at metadata level, a dependenct is an association). For instance in case of a UDP multicast a client is dependent on, lets say the server, however, there is no direct association (as we understand) between the client and the server. Usually in terms of a system, dependencies make a supplier to offer interfaces to the consumer and the consumer on its part needs to find the supplier.

Now, this dependency may be modeled as an association between two classes (in terms of instance variables). In the sense that the reference to the supplier may be retained by the consumer. Or it may be passed as a parameter to a method invocation. Or, the consumer may acquire the reference at method execution and release is subsequent to that.

Ironluca

Ironlucaa at 2007-7-7 22:04:34 > top of Java-index,Other Topics,Patterns & OO Design...