Overview
This occurs when an inheritance tree depends on another inheritance tree by composition, and to create a subclass for a class, one finds that he has to make a subclass for another class. Fowler specified that this is a special case of Shotgun Surgery code smell.
Causation
This smell can happen naturally when trying to model a problem in a domain. The problem arises when these hierarchies are created artificially and unnecessarily (for example, by adding a standard prefix throughout the classes).
Problems
Requires additional work to be done, which might be redundant.
Example
1class User(ABC):
2 ...
3 functions: Functions
4
5class Functions(ABC):
6 ...
7
8
9
10class BasicUser(User):
11 ...
12
13class BasicFunctions(Functions):
14 ...
15
16
17
18
19class PremiumUser(User):
20 ...
21
22class PremiumFunctions(Functions):
23 ...
24
25# each time a new user is added, so is a new function subclass with the same prefixRefactoring
- Move Method
- Move Field
- Create Partial
- Fold Hierarchy into One
Sources
- ORIGIN1999 · ISBN 978-0201485677