As someone fairly new to OO programming, I was wondering how more experienced programmers follow the design process. As an example, let's say you want to code a simple tetris game clone in Java or Python, how do you go about determining which classes to define and whether it makes sense to declare some as abstract classes, etc.
Letting my inexperience show, I would identify the following classes:
1.) Screen or playable area on screen
2.) A square
3.) A shape (consisting of more than one square as in 2.)
4.) a keyboard key (should this even be a class?)
5.) Some text (title, scoreline, etc.)
How will you approach this design?
I answer regarding my knowledge about java.
1. 2. and 3.
- This should be ok.
- In java, you will implement a Listener on the part that require user action. In this case teh gamearea in 1.
With a (simple) game like this, I don't think I would create a class for it.
Regarding text like the titel, i would place this in the gamearea
You could argue whether there should be created a Player class to keep score and that kind.
Similar to point 4. i doubt it will give any extra benefits, except from a learning POV.
Thanks for your reply. I must say that deciding what to make into classes is the biggest stumbling block for me to get into OOP
June 28th, 2012, 06:19 AM
Thanks..it is really great information about the OO classes which helps me to solving many problems related to java..It also helps in web design .