Extracting a New Class
The Profile class defines two responsibilities:
-
Track information about a profile.
-
Determine whether and to what extent a set of criteria matches a profile.
We want to split the two responsibilities so that we have two classes, each small and adherent to the SRP. To do so, we plan to extract the code related to the matches responsibility to another class, named MatchSet. As with all refactoring, we seek an incremental path—make a small change, run the tests to make sure they still pass.
The first change: move the calculateScore() logic into MatchSet. Start by changing the code in matches() to declare the intent. Rather than call calculateScore() directly from matches(), construct a new MatchSet object with the information ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access