Extract Specialized Anemic Entity

A special case of Extract Class

Motivation

As one step of Carve Out Bounded Context (out of Monolith) you’ve found a monolithic anemic domain model. In this you have identified an anemic entity (a “data bag”) that has become too big. The decision has been made to split it.

This is often a follow up to Carve Specialized Service Out of Monolithic Service and accompanied by Carve Specialized Data Model Out of Monolithic Table.

Mechanics

  • Create empty new class in carved-out context
  • Add instance field of type new class to the old class
  • Copy to-be-moved fields from old to new class => Move Field
  • Copy first to-be-moved method to new class => Move Method
  • Replace method body in old class with a forward to method in new class
  • Step by step replace calls to the method in the old class with calls to the method in the new class
  • Delete the implementation in the old class
  • Delete now unused fields in old class
  • Repeat with other to-be-moved methods
  • Remove instance field of type new class in the old class

Example(s)