Extracts a set of aggregates which are chosen by certain cohesion criteria and moves them to a separate bounded context.
By decomposing a system into multiple bounded contexts we aim for loose coupling between the bounded context and a high cohesion within them. There are many different approaches and different coupling criteria by which the software architect may want to decompose a system into components.
See also:
This Architectural Refactoring (AR) allows to manually select the aggregates which should be extracted by any coupling criteria or Non-functional Requirements (NFR). The goal of this AR is to isolate a set of aggregates within a new bounded context by an individual criterion.
Inverse AR's:
- The selected bounded context must contain at least two aggregates.
- One bounded context.
- A selection of aggregates which shall be extracted to a new bounded context.
- A new bounded context containing the selected aggregates.
The following two CML snippets show an example input and output illustrating how this AR works.
The following bounded context contains three aggregates:
/* With a right-click on the 'PolicyManagementContext' bounded context you can execute the 'Extract Aggregates by Cohesion'
* refactoring. A dialog will pop up which allows you to select the aggregates to be extracted. You can further specify
* the name of the new bounded context. For example: As architect you may want to extract the 'Offers' aggregate due
* to other differing availability requirements.
*/
BoundedContext PolicyManagementContext implements PolicyManagementDomain {
type = FEATURE
domainVisionStatement = "This bounded context manages the contracts and policies of the customers."
responsibilities = "Offers, Contracts, Policies"
implementationTechnology = "Java, Spring App"
Aggregate Offers {
Entity Offer {
aggregateRoot
int offerId
- Customer client
- List<Product> products
BigDecimal price
}
}
Aggregate Products {
Entity Product {
aggregateRoot
- ProductId identifier
String productName
}
ValueObject ProductId {
int productId key
}
}
Aggregate Contract {
Entity Contract {
aggregateRoot
- ContractId identifier
- Customer client
- List<Product> products
}
ValueObject ContractId {
int contractId key
}
Entity Policy {
int policyNr
- Contract contract
BigDecimal price
}
}
}
Applying the AR Extract Aggregates by Cohesion with the aggregate selection [ Offers ] produces a new bounded context with the Offers aggregate:
BoundedContext PolicyManagementContext implements PolicyManagementDomain {
domainVisionStatement = "This bounded context manages the contracts and policies of the customers."
responsibilities = "Offers, Contracts, Policies"
implementationTechnology = "Java, Spring App"
Aggregate Products {
Entity Product {
aggregateRoot
- ProductId identifier
String productName
}
ValueObject ProductId {
int productId key
}
}
Aggregate Contract {
Entity Contract {
aggregateRoot
- ContractId identifier
- Customer client
- List<Product> products
}
ValueObject ContractId {
int contractId key
}
Entity Policy {
int policyNr
- Contract contract
BigDecimal price
}
}
}
/**
* New bounded context after applying 'Extract Aggregates by Cohesion' to 'example-input.cml'
* with the following parameters:
* - New bounded context name: 'SalesBoundedContext'
* - Selected aggregates: 'Offers'
*/
BoundedContext SalesBoundedContext {
Aggregate Offers {
Entity Offer {
aggregateRoot
int offerId
- Customer client
- List<Product> products
BigDecimal price
}
}
}
- Example input source: example-input.cml
- Example output source: example-output.cml