Skip to content

Latest commit

 

History

History

AR-08-Extract-Shared-Kernel

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

AR-8 Extract Shared Kernel

Extracts a new Bounded Context from a Shared Kernel relationship. It further established two upstream-downstream relationships so that the existing Bounded Context can use the 'shared' functionality.

Context & Rationales

The Shared Kernel pattern describes a close relationship between two Bounded Contexts which share a certain part of their domain models. The pattern is typically implemented as a shared library which is maintained by both teams. However, both teams depend on that shared code and each team has to deal with changes of the other one. If such a shared library gets very big and difficult to maintain it may be better to create a separate Bounded Context for it. A dedicated team may maintain the model within this new Bounded Context.

Goal

This Architectural Refactoring (AR) extracts a Shared Kernel into a new Bounded Context. The resulting Context Map will no longer contain the Shared Kernel relationship, but two new upstream-downstream relationships between the new and the existing two Bounded Contexts. This AR can be applied if a Shared Kernel gets big, difficult to maintain, and it may be better to have a new team maintaining this shared part of the domain model in a separate Bounded Context. This may increase the autonomy of all involved teams.

Preconditions

  • Your model needs at least two bounded contexts which are in a Shared Kernel relationship.

Input

  • The Shared Kernel relationship.

Output

  • A new Bounded Context for the shared domain model parts and two new upstream-downstream relationships between the new and the existing two Bounded Contexts.

Example

The following two CML snippets show an example input and output illustrating how this AR works.

Input

The input Context Map:

ContextMap InsuranceContextMap {
  type = SYSTEM_LANDSCAPE
  state = TO_BE
  
  contains PolicyManagementContext
  contains DebtCollection

  /* With a right-click on the Shared Kernel relationship ([SK]<->[SK]) you can execute the 'Extract Shared Kernel' 
   * refactoring. It will create a new Bounded Context for the shared code (content of new Bounded Context has to
   * specified manually). Two new upstream-downstream relationships will be created to connect the existing Bounded
   * Contexts with the new one. After applying this AR, you can use the 'Rename Element' refactoring to change
   * the generated name of the new Bounded Context.
   */
  PolicyManagementContext [SK]<->[SK] DebtCollection {
    implementationTechnology = "Shared Java Library, Communication over RESTful HTTP"
  }

}

BoundedContext PolicyManagementContext {
  /* ... */
}

BoundedContext DebtCollection {
  /* ... */
}

Output

Applying the AR Extract Shared Kernel removes the Shared Kernel relationship, creates a new Bounded Context for the shared domain model parts, and establishes two new upstream-downstream relationships between the new and the existing Bounded Contexts:

ContextMap InsuranceContextMap {
  type = SYSTEM_LANDSCAPE
  state = TO_BE
  
  contains PolicyManagementContext
  contains DebtCollection
  contains PolicyManagementContext_DebtCollection_SharedKernel

  /* New relationships generated by the 'Extract Shared Kernel' AR: */
  
  PolicyManagementContext_DebtCollection_SharedKernel [ U ] -> [ D ] PolicyManagementContext

  PolicyManagementContext_DebtCollection_SharedKernel [ U ] -> [ D ] DebtCollection

}

BoundedContext PolicyManagementContext {
  /* ... */
}

BoundedContext DebtCollection {
  /* ... */
}

/* New Bounded Context generated by the 'Extract Shared Kernel' AR. After applying the AR, the Bounded Context can
 * be renamed with the 'Rename Element' refactoring. The user can further specify the comment parts here after applying 
 * the AR (create new Aggregates and entities or move them from existing contexts to this one). 
 */
BoundedContext PolicyManagementContext_DebtCollection_SharedKernel

Example Sources

Further documentation