ContextMapper / context-mapper-dsl

ContextMapper DSL: A Domain-specific Language for Context Mapping & Service Decomposition
https://contextmapper.org/
Apache License 2.0
215 stars 28 forks source link

Allow annotations of relationships in CML to be shown in generated PUML #319

Closed StevenVanDijk closed 2 years ago

StevenVanDijk commented 2 years ago

This change is a simple way to add custom labels to the relationships that are generated in the class diagram.

This CML:

BoundedContext CustomerManagementContext {

    Aggregate Customers {
        Entity Customer {
            aggregateRoot

            "lives at" - @Address address

            * void anotherMethod("uses" @Name name);
            "needs something" * @ReturnTypeEntity yetAnotherMethod();
        }

        Entity Address {
            String name
        }

        ValueObject Name {
            String first
            String last
        }

        Entity ReturnTypeEntity {
            int i
        }
    }
}

generates this PUML:

@startuml

skinparam componentStyle uml2

package "'Customers' Aggregate" <<Rectangle>> {
    class Customer <<(A,#fffab8) Aggregate Root>> {
        Address address
        void anotherMethod(Name name)
        ReturnTypeEntity yetAnotherMethod()
    }
    class Address <<(E,DarkSeaGreen) Entity>> {
        String name
    }
    class Name <<(V,DarkSeaGreen) Value Object>> {
        String first
        String last
    }
    class ReturnTypeEntity <<(E,DarkSeaGreen) Entity>> {
        int i
    }
}
Customer --> Address : lives at
Customer --> Name : uses
Customer --> ReturnTypeEntity : needs something

@enduml

However, maybe a rethink of the generation of relationships is in order. The References in Parameter and ReturnType that are used to generate the relations are actually dependency relations, not associations that express a deep semantic relationship. And it is debatable whether you always want to have all those dependencies in your class diagram, it can become quite cluttered. Is it possible to have a means for configuration in the CML file, so the generator can produce different variants based on what the user wants?

Maybe extending the grammar is a better idea, so users can model relationships themselves. What do you think?

Another thing that I see is that having a Reference for a collection type (e.g. - Set<@Book> books) generates an aggregation relationship (i.e. Order o-- Book : books). Shouldn't that be composition? Isn't any collection with a reference to an entity in the same aggregate composition and a reference to another aggregate aggregation?

StevenVanDijk commented 2 years ago

Closing since it has been superseded by PR 320