TL;DR: Don't focus on accidental properties. You won't need many of them.
- Create attributes only to support your methods (behavior).
Whenever they want to model a person or an employee, junior programmers or students add an attribute 'id' or 'name' without thinking if they are really going to need them.
We need to add attributes 'on-demand' when there's enough evidence. Objects are not 'data holders'.
class PersonInQueue attr_accessor :name, :job def initialize(name, job) @name = name @job = job end end
class PersonInQueue def moveForwardOnePosition # implement protocol end end
We can detect unused attributes.
But in many cases, we need an excellent designer to validate the actual need.
Start designing your objects from the protocol.
Add attributes only when needed.
Object thinking focuses our attention on the problem space rather than the solution space.
This article is part of the CodeSmell Series.