I have always seemed to have trouble figuring out if I should use a class or not. Here is some code (from the Dungeon Crawl exercise): http://codepad.org/RyvduP6E
As you can tell by my top comments (most of them are purely for personal notes) I want to add a two player element so the idea of a class came up. Should I create a class? Or simply add more functions? Also, if there is some way to tell whether or not to use a class, I would greatly appreciate someway I could know for the future. Thanks.
One rule of thumb is, if you can identify something as a noun, it has potential for being a class.
If you can identify a verb/action, it has potential for being a method.
Just glancing quickly at your code for a few seconds, Player, Blank, Trap, Treasure, Character can all be classes. functions can be turned into methods for those classes.
Thanks for the rule. I could never grasp when to use classes. To be honest, I seem to take a while to grasp "when-to" much harder than "how-to". It's going to be a lot of re-writing.
I don't know about "Blank" being a class. I would think that each class would have their own coords inside them so a blank square would just be the absence of something there.
With OOP, your programming sequence can become very different, especially if you do it together with TDD (test-driven development).
It's kind of like:
1. Define what objects/Classes you need to separate out functionality (classes are like records or structs)
2. Define what method shells (just the signatures) you need for those classes for them to do useful work/provide services
3. Write tests for 2.
4. Implement those methods until your tests are all green (clear)
5. Continue to 1. by writing higher level classes that call the methods that you have verified work as you expect, with testing, of course.
It tends to be much more bottom up rather than top down, and takes some time to get used to.