Finding Better Homes for Our Methods
Learn how to refactor the methods such that they are placed in relevant locations.
We'll cover the following
Our loop is a bit easier to read now, but the newly extracted code in matches()
doesn’t have anything to do with the Profile
object itself. It seems that either the Answer
class or the Criterion
class could be responsible for determining when one matches another.
Move the newly extracted matches()
method to the Criterion
class. The Criterion
objects already know about Answer
objects, but the converse is not true. If we were to move matches()
to Answer
, we’d have a bidirectional dependency which is not ideal.
Here is matches()
in its new home:
Get hands-on with 1200+ tech skills courses.