Class diagram generates duplicate class exporting to image

0 votes
asked Oct 18, 2014 in Bug by galindale (120 points)

Hello,

I send you a class diagram example which image generates a duplicate class "Source" in the package A instead of printing a arrow from class "Target" (package B) and existing class "Source" (package A).

If there is some error in my sample code, I would like to know it, please.

Thank you very much.

Best regards,

Alejandro.


 
@startuml
 
package "A" {
    class Source {
        att : string
    }
}
 
package "B" {
    class Target {
        att : string
    }
 
    Target "0..*" --> "0..1" A.Source
}
 
@enduml

1 Answer

+1 vote
answered Oct 20, 2014 by plantuml (295,000 points)
selected Oct 20, 2014 by galindale
 
Best answer

 
Short answer:
You should use namespace instead of package:
 
@startuml
namespace A {
    class Source {
        att : string
    }
}
namespace B {
    class Target {
        att : string
    }
    Target "0..*" --> "0..1" A.Source
}
@enduml


The explanation is here: http://plantuml.sourceforge.net/classes.html#Namespaces

This is due to the fact that "package" in PlantUML does not define a namespace (and this is very different of what's happen in java's packages).

Nevertheless, your example shows a bug in PlantUML, but it's because you mixed up package with namespace (using A.Source).
The situation is not easy to fix, so we are waiting for having a good way of solving thoses package/namespace issues.

 

...