Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlexis Ruiz
9,237 PointsWhere's the logic behind Private Game game;?
So, I understand that in order to use the Game class methods, we need to create a game object, but in previous videos you told that we needed to create objects following this syntax:
Class nameOfObject = new construct(Input);
This sintax makes sense, we first declare the type, then the name of the variable, then we call the construct and then we put some information into it. But I haven-t found the logic behind declaring a private Game type variable in the prompter class and then, in the constructor parameter, expect a Game type variable named whatever (In this case it's also called "game" in order to confuse us more I guess :P ) and then put that value in the private Game type game variable that we declared previously. Finally, on our main class, we need to first create the game object, and then the name of this object should to be put in our Prompter constructor parameter.
1st - Why are we matching the name of our created object with the private game variable that we created? I don't even see why the name of our object by itself would have any value at all.
2nd - Why would we bother to follow all these steps instead of just creating the game object as we did in our main class?
P.S. I already understood it by just writing this question LOL. I will just leave it here and maybe someone else will also understand the logic by just following what I typed. I believe that THE KEY PART IS "I don't even see why the name of our object by itself would have any value at all.
So, let me see if I'm correct. Basically, when we create our new object in our main class, the name of the variable stores some kind of memory address that we can use whenever we type "game". We then pass this address value to our private Game type created variable so we can then also use it in our Prompter class. Am I correct?