|
I cannot figure out the reason why a static variable is necessary for PongGame. In the PongGame.jack, a static variable 'instance' is declared and it is substituted for a local variable 'game' in the Main.jack by the following codes.
function void main(){
var PongGame game;
do PongGame.newInstance();
let game = PongGame.getInstance();
....
On the other hand, a static variable is not seen in the SquareGame, where an object is generated by the following codes.
function void main(){
var SquareGame game;
let game = SquareGame.new();
...
Why cannot we write the Pong code just as we do for the SquareGame?
I understand that the static variable is defined at the class level and can be accessed by every object which is generated from the class. However, I cannot understand the necessity to generate and use the static variable 'instance' for Pong.
Ichiro
|