I have a codebase where some classes contain both "essential" business logic, and "incidental" complexity. I am considering a refactor where I leverage inheritance to improve the readability and maintainability of the code. However, it's not clear if the base class should be the one containing the non-core logic (and its child implements the core logic) or the other way around.
To illustrate my situation, consider the following class:
class MyDoEverythingClass:
def __init__(self, ...):
...
def calculate_tax(self):
...
def validate_data(self):
...
def persist_to_file(self):
...
def plot(self):
...
In this case the only "real" logic here is the calculate_tax method - so I could refactor this as:
class CoreLogic:
def __init__(self, ...):
...
def calculate_tax(self):
...
class ExtendedFunctionality(CoreLogic):
def validate_data(self):
...
def persist_to_file(self):
...
def plot(self):
...
or the other way around:
class NonCoreLogic:
def __init__(self, ...):
...
def validate_data(self):
...
def persist_to_file(self):
...
def plot(self):
...
class CoreLogic(NonCoreLogic):
def calculate_tax(self):
...
Are there reasons to favour one over the other?