AR-7: Merge Bounded Contexts
Merges two bounded contexts together. The result is one bounded context containing all the aggregates of the two input bounded contexts.
Context & Rationales
By decomposing a system into multiple bounded contexts we aim for loose coupling between the bounded context and a high cohesion within them. However, sometimes a decomposition may be too fine-granular and merging bounded contexts with a high coupling together improves the cohesion within the corresponding resulting bounded context.
This Architectural Refactoring (AR) merges two bounded contexts together. The resulting bounded context contains all aggregates of the two input bounded contexts. It can be applied if two bounded context are tightly coupled and the aggregates somehow belong together. This may improve the cohesion within the resulting bounded context.
- By applying this AR multiple times you may end with one single Bounded Context and an empty Context Map (no relationships).
- The AR merges all Bounded Context attributes (such as exposed aggregates, implementation technology, etc.) which are possible
to merge. However, there are still attributes which cannot be merged, such as the name or the domain vision statement.
- All attributes which cannot be merged are taken from the first Bounded Context (by default) selected in the dialog (see screenshot below).
- You have to use the corresponding checkbox on the input dialog, if you want to take the attributes from the second Bounded Context.
- AR-4: Extract Aggregates by Volatility
- AR-5: Extract Aggregates by Cohesion
- AR-2: Split Bounded Context by Use Cases (may need multiple merges to completely revert)
- AR-3: Split Bounded Context by Owner (may need multiple merges to completely revert)
- Your model needs at least two bounded contexts to merge.
- Two bounded contexts.
- One bounded context containing all aggregates of the two input bounded contexts.
The following example illustrates how this AR can be applied. The corresponding sources can be found in our examples repository.
The following model contains two bounded contexts with one aggregate each. Therefore the AR is available on both bounded contexts:
After triggering this refactoring, a dialog pops up on which you can choose with which other bounded context you want to merge:
The resulting model contains one bounded context with both aggregates of the selected bounded contexts:
- You can find the CML sources for this AR example here.