DEV Community

Discussion on: JS Coding Patterns that give you away as a Junior Developer

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Best example is in games where an object has speed + angle or speed_x + speed_y depending on how you want to look at it. It's nice to access either of them as if they were actual variables and not think about how the object stores its velocity vector internally.

That being said, getters/setters go against the "Tell, don't ask" principle. Too much getters/setters are usually a sign that your objects logic might be leaking into different objects, which is very bad in terms of object orientatino.