Game Development Reference
In-Depth Information
Figure 12-11 . Change declaration statement for HBox object named buttonContainer from a static modifier to private
I had originally declared these fields static because I had read on the Internet, on
several of the Java coding sites, that this is an “optimization trick,” which allows the
JVM to set aside fixed areas of memory, and make the code run more optimally. I have
decided to make the objects for my game as encapsulated as possible first, here during
the development process, and then look at optimization later on, if and when it be-
comes necessary.
As long as we are making our InvinciBagel.java class completely encapsulated,
let's make the other variables private as well. I tested this game after making each of
the variables (after the Bagel iBagel declaration) private, and it ran just fine. When I
make the Bagel iBagel private, the game hangs on a white (background color) screen,
so I left the Bagel iBagel declaration package protected (no access control modifier
keyword signifies package protected access).
Making the Remaining Variables Private: Finish Encap-
sulating InvinciBagel Class
 
Search WWH ::




Custom Search