Closed nkcr closed 4 years ago
Hi, thanks for your comment. I believe the one piece you are missing is aggregation. It could be kind of confusing, but for the context of this app, Composition means type Embedding composition. In other words you will need to embed one structure into another to see the composition link. In the same way MyStruct2 includes MyStruct1
//MyStruct2 will be direclty composed of MyStruct1 so it will have a composition relationship with it
type MyStruct2 struct {
MyStruct1
}
In the case of this code
//MyStruct3 will have a foo() function but the return value is not a bool, so it will not have any relationship with MyInterface
type MyStruct3 struct {
Foo MyStruct1
}
Foo is a field of MyStruct3. That kind of representation, although it is a composition, it is done through an aggregation link. Aggregations are optional in the command line interface. They are only shown if you include the -show-aggregations
flag in the command line call. Have you tried that?
Ok, I finally made it work with the -show-aggregations
flag. This was something I already tried before but apparently the go get github.com/jfeliu007..
commands are not fetching the lastest version, so I was using an outdated one.
I had to manually download the release and build it on order to have the latest version and make aggregation work.
I’ll take a look at that to see what’s happening. Thanks. 😁
Same issue here with GoPlanUML v1.5 and the show-aggregations
option.
(Simplified main.go)
package main
// HtmlElement
type HtmlElement struct {
name, text string
elements []HtmlElement
}
type HtmlBuilder struct {
rootName string
root HtmlElement
}
Puml
@startuml
namespace main {
class HtmlBuilder << (S,Aquamarine) >> {
- rootName string
- root HtmlElement
+ String() string
+ AddChildFluent(childName string, childText string) *HtmlBuilder
+ Clear()
}
class HtmlElement << (S,Aquamarine) >> {
- name string
- elements []HtmlElement
- string(indent int) string
+ String() string
}
}
@enduml
I just have to say that even if composition and aggregation may look one and the same, the big difference is that if a composed object is destroyed, then the composing object will be as well. This is not the case of an Aggregation. So, embedded fields (unnamed), named field (by struct, interface, or a pointer to a struct) can all be either part of a composition or an aggregation depending on other relationships where a field would be involved too. From my perspective, it's an important distinction to make because a nice diagram may help to focus our search when there is a memory leak in the app for example. Aside from that, it's working pretty well and I really appreciate the effort :)
@BigBoulard private aggregations are not rendered unless explicitly ask for it with the -aggregate-private-members options.
Try goplantuml -show-aggregations -aggregate-private-members ./
This is the result I get with the code you presented
@startuml
namespace main {
class HtmlBuilder << (S,Aquamarine) >> {
- rootName string
- root HtmlElement
}
class HtmlElement << (S,Aquamarine) >> {
- name string
- elements []HtmlElement
}
}
"main.HtmlBuilder" o-- "main.HtmlElement"
"main.HtmlElement" o-- "main.HtmlElement"
@enduml
The project makes a distinction between aggregations and composition even at the visual level. :)
try this code
package main
import "os"
// HtmlElement
type HtmlElement struct {
name, text string
elements []HtmlElement
os.File
}
type HtmlBuilder struct {
rootName string
root HtmlElement
}
You will see a difference in how the connections are rendered. os.File
will be rendered as a composition with a filled arrow.
@nkcr , @BigBoulard is this issue still relevant?
If I try to run the example in the README.md, the composition with
MyStruct3
is not rendered (using go v1.12.6):How to reproduce
save the following to a file:
Then generate the plantuml:
The diagram I get is the following: