Tuesday, November 3, 2009

Classes

Classes are a form of structuring software projects in modern programming languages. Read more on object-oriented design (if interested).

The T9.3 task will not be checked (there are no points for it) but just to remind you that the described feature should be in your project. T9.2 is a simpler task dealing only with modification of the example. Of course, you could do it by changing your project (like having some graphics moved to another class), which is more than the T9.2 calls for. If you understand classes well then I would suggest to do T9.2 as it is required (will be a small piece of work for those who understands classes) and then without hurry redesign your project into may be several classes (the better use of technology - the higher the grade for the project will be). One class might handle the interface, another handles logic of the control panel, and the third one deals with the game engine (as game state generation, getting user input, and win/loose calculation with no connection to the GUI interface). But if you want to start with one class for now (like some graphics in your project) you can do it. The class design that I just described corresponds to the modern MVC pattern (read about Model View Controller pattern on the Web). The View here will be not just the picture but the whole layout (although art could be a small subclass). The picture will probably change in its implementation when we get to the threads (as another form of concern separation) anyway. The general rule is to keep something in a separate class (object-oriented design), which will have a life (changes) of its own. So if you plan to play with picture by changing it as a result of the event processing - then it should be another class serving the proper image based on the user choices and resulting system’s reaction.

A simple description of the typical class structure and a simple example are on pp.237-239.

If you want to know more about classes – read: http://java.sun.com/docs/books/tutorial/java/javaOO/classes.html . Somewhat more advanced tutorial is here: http://home.cogeco.ca/~ve3ll/jatutor4.htm . For deeper understanding of classes: http://leepoint.net/JavaBasics/oop/oop-10-intro.html see all pages and also the whole chapter 3 in http://docstore.mik.ua/orelly/java/javanut/ch03_01.htm .

No comments:

Post a Comment