-
Notifications
You must be signed in to change notification settings - Fork 88
guide eto cto
For each persistent entity «BusinessObject»Entity
we create or generate a corresponding entity transfer object (ETO) named «BusinessObject»Eto
. It has the same properties except for relations.
In order to centralize the properties (getters and setters with their javadoc) we create a common interface «BusinessObject»
implemented both by the entity and its ETO. This also gives us compile-time safety that
bean-mapper can properly map all properties between entity and ETO.
If we need to pass an entity with its relation(s) we create a corresponding composite transfer object (CTO) named «BusinessObject»«Subset»Cto
that only contains other transfer-objects or collections of them. Here «Subset»
is empty for the canonical CTO that holds the ETO together with all its relations.
This is what can be generated automatically with CobiGen.
However, be careful to generate CTOs without thinking and considering design.
If there are no relations at all a CTO is pointless and shall be omitted.
However, if there are multiple relations you typically need multiple CTOs for the same «BusinessObject»
that define different subsets of the related data.
These will typically be designed and implemented by hand.
E.g. you may have CustomerWithAddressCto
and CustomerWithContractCto
. Most CTOs correspond to a specific «BusinessObject»
and therefore contain a «BusinessObject»Eto
. Such CTOs should inherit from MasterCto
.
This pattern with entities, ETOs and CTOs is illustrated by the following UML diagram from our sample application.
This documentation is licensed under the Creative Commons License (Attribution-NoDerivatives 4.0 International).