Getters And Setters Customization

Getters and Setters may accept more than 1 arguments and have customized logic.

To do that functions acting as getters and setters need to be created.

Customized Getter

Output:

Explanation:

  • The customized getter (defined at lines 3 - 9) accepts one parameter - roundUp.
  • The getter for area property is used at line 25. It's function does not accept any arguments. This means that the function behaviour cannot be dependant on arguments (like roundUp).

Customized Setter

Output:

Explanation:

  • At line 33 the age setter (defined at lines 26 - 28) is used. It accepts only one parameter.
  • The setNames setter accepts many parameters and can have a behaviour based on the accepted parameters.