How do I create "Composite" pattern using PlantUML?

0 votes
asked Nov 11 in Question / help by SomervilleTom (140 points)

I would REALLY like to use `PlantUML` to create the diagrams used by my tiny team for all the usual reasons. I'm a senior developer with proficiency in most modern tools and systems. Our development is all done on Rocky Linux systems that run on AWS EC2 instances. We want to use `PlantUML` to create `.png` and `.svg` diagrams for a variety of internal and external documents.

After a day of thrashing, I've decided to ask for help.

My test case is the classic "Composite" pattern from "Design Patterns" (the "Gang of Four" text). I want to generate a drawing that looks like this:
 

Composite Pattern (.gif)

After much searching, reading, head-scratching and trial-and-error, here is the closest I've been able to come:

@startuml compositePattern
object Client
object Component
object Leaf
object Composite
skinparam linetype ortho

'Component *-- Client
Client -* Component
Component <|- Leaf
Component <|- Composite
Composite o-- "1" Component : children
@enduml

This looks like the following:
 

Failed Composite Pattern (.puml)

Well, at least it has the four participants.

Is there a tutorial someplace? I've been through the docs and tried all kinds of things. Here's what I haven't been able to do:

  1. The `Client` element should at the left, even with the `Component` element.
  2. The 'Leaf` and `Composite` elements should be below the `Component` element, and should share a common arrow as in the example shown above.
  3. I'd REALLY like the "children" reference to resemble the original example. Its label should at least be obviously associated with the aggregation arrow
  4. The elements should all have the same width

I'd really like a reference or citation to some resource that can help me to at least come close to the example image.

1 Answer

0 votes
answered Nov 11 by The-Lu (36,200 points)

Hello S.,

Here is an attempt (but that is not the best), with use of:

  • class instead object
  • groupInheritance
  • minClassWidth
@startuml
'skinparam linetype ortho
skinparam groupInheritance 2
skinparam minClassWidth 100
hide circle

class Client
class Component
class Leaf
class Composite

Client -* Component
Component <|-- Leaf
Component <|-- Composite
Composite o-- "1" Component : children
@enduml

If that can help (that is not perfect, perhaps some issues [about object, linetype,... ] must be post on the forum...),

See some existing issues here:

Regards,
Th.

...