This is the first article in a series I'm doing called DevBits. These are mini-articles that will show how programming concepts can be applied.
Youโre making an RPG.
You have a Character
(class) who has health
and armor
(private fields).
Among other things, a Character
can heal()
or takeDamage()
(public methods).
heal()
increases health
.
takeDamage()
decreases health
based on armor
.
Other objects are not able to modify the health
of a Character
directly, rather, they can only call the methods exposed by the class.
This is encapsulation.
Top comments (0)