No Classes with More Than Two Instance Variables
Limiting state to two instance variables dramatically increases cohesion — if you need more, decompose into a hierarchy of collaborating objects.
Why this matters
Every extra instance variable beyond two is a sign of a hidden concept waiting to become its own class. A class with seven fields like firstName, lastName, street, city, country, email, and phone is really four concepts — Name, Address, Location, and Contact — jammed into one. Decomposing them reveals the domain structure and dramatically increases cohesion: every method in a two-variable class uses both variables, which is the definition of maximum cohesion.
Code Challenge
Study the messy code, try to refactor it, then reveal the clean version.
💡Key takeaway
Every extra instance variable beyond two is a hidden concept waiting to become its own class. Decompose until each class has at most two fields — the resulting hierarchy will reveal the true structure of your domain.
🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.
Hint: Every extra instance variable beyond two is a sign of a hidden concept waiting to become its own class.
✗ Your version