clean-code-objects-vs-data
Installation
SKILL.md
Objects and Data Structures
Data abstraction
Hiding implementation isn't just a matter of putting a layer of getters and setters over fields. Real abstraction exposes the essence of the data, not its storage. Compare:
point.x,point.yversuspoint.set_cartesian(x, y)andpoint.r,point.theta, which together hide whether storage is cartesian or polar.vehicle.fuel_tank_capacity_gallonsandvehicle.gallons_of_gasolineversusvehicle.percent_fuel_remaining().
Don't blindly add getters and setters for every field. Think about the most abstract way to represent what the client needs.
The anti-symmetry
- Objects hide their data behind abstractions and expose functions that operate on it.
- Data structures expose their data and have no meaningful behavior.
They're opposites, with opposite strengths: