MagicDraw UML and SysML Plugin eSchool
Motto: "Learn good ways to work with MagicDraw UML and its SysML Plugin !"
About the eSchool
UML2 in MagicDraw
MagicDraw UML tips
MagicDraw SysML Plugin
MagicDraw for Java
MagicDraw for XML
Advanced UML and SysML Training

Does the Analysis option to create Dependencies between Classifiers also catch local variables in methods ?

Not every dependency of Main on the other classes in the javavariables example is revealed by just using Associations, because some of the methods of Main use Java local variables:



static public Thing newThingDefault() {
Thing t = new Thing_();
return t;
}



@Lazy
final static protected Factory factory() {
if ( factory_ == null ) {
factory_ = new Factory_(); // by default choose default factory
}
return factory_;
}


Did the Analysis option to create dependencies between Classifiers on reverse catch these as virtual Dependencies (see diagram) ?:

  • it gave only {n=1} for Thing_ (which comes from an explicit private field anyway)
  • it does not find a Dependency on a Factory_ in factory() at all !

So it seems that the Analysis reverse option does not penetrate methods (although the method-based reverse for generating sequence diagrams can).


Exposing Dependencies between Java methods and Classifiers

There are at least the following strategies for dealing with this situation to achieve a graphical UML model communicating this Dependency information:

  1. Create Dependency (or Usage) relationships "by hand" in the UML model from methods to the Classifiers they use (see example below):
    • WARNING: this can be very error prone and is not automatically synced with the code on future reverse.
    • TIP: if you do this I recommend that you clearly stereotype them as «manual» to show they are not automatically reversed.
  2. Code in a UML-friendlier way by avoid local variables wherever possible; expose them explicitly as fields:
    • I am a fan of this approach, as the tiny loss in Java efficiency is more than compensated by the increased readability of graphical, associative UML diagrams that correspond well to the reverse engineered Java.


Visit also:

Image: 
Search
MagicDraw UML for Java software engineering