Explicit Getters and Setters For Implementation Phase

Hello!

We wanted clarification about whether we are strictly required to keep attributes private and provide explicit getter and setter methods (e.g., getId(), setId()), or if it is acceptable in implementation to use standard properties (e.g., public (non-private) val fields accessed directly instead of getters, or using var instead of explicit setters).

We want to make sure our implementation aligns with what was taught in the lectures(encapsulation and other principles) while avoiding redundant functions.

It would be really helpful if someone could clear things up! Thank you!

1 Like

Hi,

its ok to use the properties (val & var) for fields you want to be accessible from outside. However for attributes that are only used within the class you should still use the private attributes.

1 Like