Extract Class

Dividing responsibilities into classes is the primary way to manage complexity in object-oriented software. Extract Class is the primary mechanism for intro- ducing new classes. This refactoring takes one class and splits it into two by moving one or more methods and instance variables into a new class.

  1. Create a new, empty class.
  2. Instantiate the new class from the original class.
  3. Move a method from the original class to the new class.
  4. Repeat step 3 until you’re happy with the original class.

Drawbacks

  • Extracting classes decreases the amount of complexity in each class, but increases the overall complexity of the application. Extracting too many classes will create a maze of indirection which developers will be unable to navigate.
  • Every class also requires a name. Introducing new names can help to explain functionality at a higher level and facilitates communication between developers. However, introducing too many names results in vocabulary overload, which makes the system difficult to learn for new developers.