DEV Community

Discussion on: OOP Principles For Dummies

Collapse
 
kabircse profile image
Kabir Hossain • Edited

I have a question on your given line

"Imagine that one of the players got access to this client, and wanted to cheat by changing the game status and reward.
public static void client() {
Quest quest = new Quest('Goblin Slaying', 190, 3);
quest.reward = 1000000000;
quest.status = 5;
}
Right now this code is valid, because our variables are publicly accessible. Another problem here is that our "hacker" set the status to 5 which doesn't exist, and thus our game breaks."

My questions are given below:

  1. How player accessed the client because it is an application and the code is generated already and the system just call the instance?

  2. How hacker will access and alter this code? Because the application is generated an instance of this class and just run only.

Collapse
 
tamerlang profile image
Tamerlan Gudabayev

This was hypothetical, but it may be possible to inject java code to some game but idk, I used this example to explain encapsulation.