Modeling uses relation for static method calls in a class diagram
1 posts in topic
Flat View  Flat View

Posted By:   Suresh_Addagalla
Posted On:   Tuesday, July 3, 2001 09:28 PM

How do I represent the following situation in a class diagram.
1. Class A calls a static method of Class B.
2. Class A instantiates Class B in one of its methods and calls it's methods through that object.
I guess in both the cases it is a uses relation(dependency). But how do I differentiate between the two cases? Is there a better alternative than showing a uses relation between A and B?

Re: Modeling uses relation for static method calls in a class diagram

Posted By:   jim_conallen  
Posted On:   Thursday, July 5, 2001 11:57 AM

Firstly - what you are asking seems rather
dynamic. Method calls are modeled in sequence and collaboration diagrams
with messages between objects (with static operations being messages to the
class object and not an instance of the class).

I suspect you are really asking how do I express these relationships in a class
diagram though. In the first case you are right the best way indicate
this is with a dependency. But remember that a dependency doesn't mean a class calls
static operations on another class - it just means that one class of object
depends on the other, and that changes to the other's interface or structure is of interest
to the first (or more obviously: one class depends on another). Modeling
actual methods calls can only be done in an interaction diagram.

In the second situation, if you have a static
member variable in Class A of type B you would represent this as a normal
association, where the role specifier is either underlined or prefixed with a
dollar sign to indicate that this is a static member and not an instance

If you don't have a static member variable, and
instead instantiate and manage the object instance's lifecyce in the context of
one static method call, then you could just draw a second dependency to Class B
and attach a note to it, indicating why it was different. Personally I
wouldn't do it that way, but rather indicate any wierdness in a note, or most
likely in an interaction diagram.

Remember the class diagram can only show structure
and structural relationships between the things in your application, and not
dynamic things.

About | Sitemap | Contact