DEV Community

Discussion on: Avoid getters and setters whenever possible

Collapse
 
hack2root profile image
Artur Mustafin • Edited

It so naive for you to misunderstanding how getters and setters work;

The reality is that getters/setters have at least exactly the same security as of any over accessor modifiers.

Moreover, getters/setter have more security other the items thy control when geclared properly.

Getter/Setter is an abstracton of control, allowing you to make some additional operations before you get into trouble with references you incapsulated class data outside of a class.

For examle, SIMPLY buuld and return a COPY of data when getter called, when needed, or clone data when setter called. It is that simple