Extract Class

From CSSEMediaWiki
Jump to: navigation, search

This is a common refactoring method, given this moniker in Martin Fowler's Refactoring book.

When a class gets larger and more complex, we can manage this complexity by breaking the large class into multiple smaller classes. As an Example, mapping software may contain Country objects. If the map simply stores the name of the country, its population, and the name of its capital city, then the class is small and manageable. However if the class is expanded to store a larger amount of information, the class will become unwieldy.

If for example we wish to store multiple historical population figures for each country, it's sensible to extract this information into a separate Population object. The provides separation of concerns, avoids the Divergent change smell, and keeps both objects small.

Personal tools