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 trialPierre-Emmanuel Turcotte
13,670 PointsGlobal constants question
Couldn't we have declared them all in the header file only along with their values? Instead of having declared them in the implementation and then making them accessible in the header file?
1 Answer
Rashii Henry
16,433 PointsDeclaring those classes within the header file is a common practice and fine. The header file (also known as the interface) is where you want to declare your variables. Simply because inside of your header file you're basically saying, 'Im giving you all the tools to work with'.
Then your implementation takes these tools (the ones that you gave it to work with), so it can implement, or work with those tools the way you intend for them to work.
To answer your question, we could have only declared them in the header file and made them accessible globally. However, the same variables that were declared and initialized within the implementation, needed to be used privately within that same class. So, in those dictionaries we wanted to pass in STATIC VARIABLES into the dictionary and NOT string literals.