DEV Community

Discussion on: Code Smell 35 - State as Properties

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I'd go as far as to say getters and setters are always a sign of bad design in OO code. Their only real purpose in that context is as a hack when business constraints don't allow for a more solid (you can also read that as SOLID) design.

Other than that, they're useful when one needs procedural segments in an otherwise OO codebase, mostly to implement some of the lower levels of the logic. Arrays just don't work well with "tell don't ask".

Collapse
 
mcsee profile image
Maxi Contieri

I agree

Both setters and getters should be avoided most of the time.

People use them thinking they are protecting their implementation but is exactly the opposite. Next Sunday's code smell is related to that