I am studying programming and although I feel like I have good knowledge in programming (been writing PHP, Javascript etc for years), I've never dived into the world of OOP. Because of this I am asking for a general answer for the situation I am in. I know that there always will be some exceptions, but I am looking for the most correct approach in this case.
Ok, so I have two classes, Game
and GameGraphics
. GameGraphics
will create an object of Game
and use all the methods it has. We recently learned that all variables a class should be private, so all the variables in Game
are accessed by GameGraphics
through getters and setters.
But, when I want to access the variables of Game
inside the Game
class, should I use the public methods, or just access the variables directly? What is the most correct approach to this?
I'm developing in Java, if that matters. And please excuse my lack of OOP-experience.