Preferred use of qualified name (absolute vs. relative names)

0 votes
asked Jan 26 in Question / help by Ansgar

Dear all, it seems that there are different ways to use qualified names (which are not well documented, unless I am mistaken). In the following simple example. I like to declare an association between the classes A and B which are in the packages p1 and p2, respectively.

PlantUML can create a duplicate of a referenced classifier, since it interprets a qualified name as a relative path unless it is prefixed with a dot or the first segment of the qualified name is already known. See below for an example. Is there a preference to use qualified names?

@startuml
' does not work: p2 is interpreted as subpackage of p1, B is duplicated
package p1 {
class A { }
A -- p2.B
}

package p2 {
class B { }
}
@enduml

@startuml
' forward declaration of p2, works
package p2 {}

package p1 {
class A { }
A -- p2.B
}

package p2 {
class B { }
}
@enduml

@startuml
' absolute qualified names using a preceding dot

package p1 {
class A { }
A -- .p2.B
}

package p2 {
class B { }
}
@enduml

@startuml
' enclosing with single root, works

package root {
package p1 {
class A { }
A -- root.p2.B
}

package p2 {
class B { }
}
}
@enduml

commented Jan 26 by The-Lu (87,580 points)

Another solution:

  • First declare elements,
  • Then declare link as:
@startuml

package p1 {
class A { }
}

package p2 {
class B { }
}

A -- p2.B
@enduml

Enjoy,
Regards,
Th.

commented Jan 26 by The-Lu (87,580 points)

Also:

@startuml
package p1 {
}
package p2 {
}

p1.A -- p2.B
@enduml
commented Jan 26 by Ansgar
Thank you for your quick answer. I would prefer a combination of your two options: declare A and B in their respective packages and use qualified names to reference them.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

[Antispam2 Feature: please please wait 1 or 2 minutes (this message will disappear) before pressing the button otherwise it will fail](--------)
To avoid this verification in future, please log in or register.
...