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 trialCody Tapp
9,667 PointsI'm having a bit of confusion with variable declaration of type "class name"
Can someone give clarification on why he declared _location with type MapLocation? I somewhat understand why he's doing it, because he's trying to reference from the MapLocation class. But what is being referenced from it? I tried looking in the class, but could not find anything remotely close to what it is referencing?
1 Answer
Steven Parker
231,198 PointsThe "_location
" variable is what is called a "backing store" or "backing variable". It's a private variable that holds a value that is normally accessed using a public property (in this case named "Location
"). The variable and property are both declared as the same type and work together.
In this app, they are used to store the location on the map of each "Invader" instance.