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.y versus point.set_cartesian(x, y) and point.r, point.theta, which together hide whether storage is cartesian or polar.
  • vehicle.fuel_tank_capacity_gallons and vehicle.gallons_of_gasoline versus vehicle.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:

Installs
1
First Seen
2 days ago