Software Design/Extract Class

From Wikiversity
Jump to navigation Jump to search

Extract Class is a general refactoring with several more specific instances which have varying positive effects but mostly the same drawbacks:

This article corresponds to Extract Class refactoring described in Refactoring.[1]

Why not[edit | edit source]

Extracting a class contributes to pointer indirection that might slow down the software if objects of the extracted class are accessed frequently. It might also make the software to use more memory or spend more time in garbage collection in environments such as JVM (both effects are manifestations of higher resource usage) if a lot of objects of the extracted class are created.

Another disadvantage of this refactoring is that it spreads the logic over more locations that makes the readers to navigate more. See practice Don't break logic into too many small functions.

Related[edit | edit source]

References[edit | edit source]

  1. Refactoring: Improving the Design of Existing Code (2 ed.). 2018. ISBN 978-0134757599. https://martinfowler.com/books/refactoring.html.  Chapter 7, "Extract Class" section