Last Revision — April 19, 2022
2 Min Read
Inappropriate Intimacy
Data Dealers
Responsibility
Between Classes
- Fate over Action (caused)
- Feature Envy (co-exist)
Martin Fowler in book (2018):
"Refactoring: Improving the Design of Existing Code (3rd Edition)"
Martin Fowler in book (1999):
"Refactoring: Improving the Design of Existing Code"
The classes should know as little as possible about each other. As Fowler put it, "classes spend too much time delving in each other's private parts" [1]. This code smell was listed in 1999 as Inappropriate Intimacy and is no longer listed in the 2018 version of the book under the same name. It was replaced by the term Insider Trading code smell, possibly to make the change - that now the classes
were generalized to modules - more noticeable (similarly to the wording change in Feature Envy).
The concept stays the same - instead of reaching for each other's secrets, modules/classes interchange too much information and implementation details. In other words, this occurs whenever a module/class has too much knowledge about the inner workings or data of another module/class.
At first, two classes could intertwine, but over time, they have coupled. [2]
The modules between themselves should know as little as possible.
Developers cannot reuse intertwined classes in isolation.
Mocking is required.
@dataclass
class Commit:
name: str
def push(self, repo: Repo):
repo.push(self.name)
def commit(self, url: str):
...
@dataclass
class Repo:
url: str
def push(self, name: str):
...
def commit(self, commit: Commit):
commit.commit(self.url)