Quantcast
Channel: Stories by Segun Ola on Medium
Viewing all articles
Browse latest Browse all 20

Thank you, Frank.

$
0
0

Thank you, Frank.

Getters/setters are useful for hiding the internal implementation of your class. By using a getter here, we’ve managed to conceal (sort of) the internal implementation of our class.

If a user wants to set value directly, they’ll probably do something like:

const arith = new Arithmetic();
arith.val = 50 // this won’t work because there’s no setter defined.

They have to peek under the hood to find that we’re storing the value in “arith.value” not “arith.val”. Sometimes, you want to restrict the usage of your program’s API. In this case, you only set values by performing arithmetic operations. It’s probably not that useful here though.


Viewing all articles
Browse latest Browse all 20

Latest Images

Trending Articles





Latest Images