Tuesday, March 2, 2010

Object Encapsulation



Here is an example of a Super Mario class, he has health, lives, a variable to see if he is currently suspended in air or not (isJumping) and score. These are encapsulated and can only be accessed outside the object via the functions such as SetScore(),GetScore(),SetLives(),GetLives() and more. These are called Accessors and Mutators. Accessors are the functions with the prefix "Get" and they do exactly that. They obtain the value safely to prevent errors. Mutators are the functions with the prefix "Set" and they set the value safely and everything related to that value.

No comments:

Post a Comment