Dependency between packages containing classes

0 votes
asked Feb 14, 2019 in Bug by anonymous

It is possible to create dependencies between packages

@startuml

package Application {
}

package ClientInterface {
}

package LibraryInterface {
}

package LibraryImplementation {
}

Application ..> ClientInterface
ClientInterface .down.> LibraryInterface
ClientInterface .down.> LibraryImplementation
LibraryImplementation .right.> LibraryInterface

@enduml

Which creates the diagram I intended, including the correct layout of packages and arrow directions.  However, if I try to add classes to the package contents, the layout of the diagram breaks.  The arrows are all over the place, not pointing to the right things.

@startuml

package Application {
}

package ClientInterface {
  class class1
}

package LibraryInterface {
  interface interface1
  interface interface2
}

package LibraryImplementation {
  class class2
  class class3
}

Application ..> ClientInterface
ClientInterface .down.> LibraryInterface
ClientInterface .down.> LibraryImplementation
LibraryImplementation .right.> LibraryInterface

@enduml

can you confirm that this is a bug and not something i am doing wrong?

3 Answers

0 votes
answered Feb 15, 2019 by plantuml (295,000 points)
You are doing nothing wrong.

Somehow, we are facing a limitation of GraphViz : this is how GraphViz manages edges between subgraph.

Unfortunately, we cannot really do better : so we have to live with this strange behavior.

Sorry about that!
commented Feb 15, 2019 by anonymous
It actually partially works, e.g. when all but one of the packages contains classes.  is there any workaround that can make it work?
0 votes
answered Feb 15, 2019 by zimchaa (1,040 points)

I think it might be possible to argue that packages are diagramatical elements, and connections are meant to be between the classes themselves, instead of the packages. I do know that when you add sub-elements, even to connectable things, you do get odd behaviour:

@startuml

package Application {
  class class
}

package ClientInterface {
  class class1
}

package LibraryInterface {
  interface interface1
  interface interface2
}

package LibraryImplementation {
  class class2
  class class3
}

class ..> class1
class1 ..> class2
class1 ..> class3
class1 ..> interface1
class1 ...> interface2
class2 .> interface2

@enduml

commented Feb 15, 2019 by anonymous
You could argue this but I think I would win that argument :-)

1. PlantUML supports UML
2. Dependencies between packages are allowed by uml (https://www.uml-diagrams.org/package-diagrams-overview.html)
3. UML packages can contain classes (https://www.uml-diagrams.org/package-diagrams-reference.html)
4. Therefore PlantUML should support models that include both #2 and #3

QED

Are any of the points above incorrect?

Further, if this is not supported then PlantUML should refuse to generate the diagram.
commented Feb 16, 2019 by zimchaa (1,040 points)
Fair point - you might have a bit more luck getting a nicer looking diagram using the linetype feature mentioned here:

http://forum.plantuml.net/1608/is-it-possible-to-only-use-straight-lines-in-a-class-diagram

Per this view:

http://liveuml.com/diagram/view/5c6805ef3fa83d1ca990c724

@startuml

skinparam linetype ortho

package Application {
}

package ClientInterface {
  class class1
}

package LibraryInterface {
  interface interface1
  interface interface2
}

package LibraryImplementation {
  class class2
  class class3
}

Application ...> ClientInterface
ClientInterface ..> LibraryInterface
ClientInterface ...> LibraryImplementation
LibraryImplementation .> LibraryInterface

@enduml
0 votes
answered Feb 16, 2019 by plantuml (295,000 points)
On second though, maybe there is a possible solution.

It's not working yet, but we could make it working.

The idea is to put sub-diagram into package definition. The only limitation will be that each sub-diagram will be independant : it will not be possible to draw edge between a class of some package to a another class of another package.

As mentioned, it's not working yet, but the idea is to have something like http://www.plantuml.com/plantuml/uml/TP512i8m44NtSugS8D2wBnLNWZSG5sCwri4q3Uc8IEdTBIX1Ox89oJ3_ynvf9y4Wzy62HtF3djJMUyi6XKUdZZ3Fe9InE4tl4vO5JX2NTvR9oTu9XGiQoWIg977WSy3m_8jm7CHRbH_NXSR1MnfMcX9w_VlSV6g-VRLkKYL85NKtFfnkKf7YOfuFyjGwS7-LN7jBhbk_wGK0

Would that cover your need ?
commented Feb 16, 2019 by anonymous
Yes, if i understand you correctly.  Sub-diagram in a package without relationships to other sub-diagrams is what i'm trying to accomplish.   The only thing I'm not sure about is the diagram you linked to and why the sub-diagram doesn't appear in the package -- would those embeded sub-diagrams be visible in the final solution?
commented Feb 16, 2019 by plantuml (295,000 points)
It's now fixed in last beta http://beta.plantuml.net/plantuml.jar
You should be able to use :
@startuml
package Application [
{{
  class class
}}
]

package ClientInterface [
{{
  class class1
}}
]

package LibraryInterface [
{{
  interface interface1
  interface interface2
}}
]

package LibraryImplementation [
{{
  class class2
  class class3
}}
]

Application ..> ClientInterface
ClientInterface .down.> LibraryInterface
ClientInterface .down.> LibraryImplementation
LibraryImplementation .right.> LibraryInterface
@enduml

Tell us if it's not working for you!
Thanks
commented Feb 22, 2019 by anonymous
Yes this is working, thanks!  When will it be released?
...