Thursday 25 February 2010

CRC Cards and How I Killed a Small Forest

Class, Responsibility, Collaborator. Those are the three things that go onto a CRC Card--the name of the class to be made, what that class does (including what data it stores), and which other classes this class interacts (or, as the name suggests, collaborates) with.

These cards are recommended as a tool for designing an object-oriented program. I do see the usefulness of them. That said, writing 41 CRC cards is not exactly the most entertaining way to pass time. And that includes a couple of cards that I finally decided to generalize, since some things like Ship, Vehicle, and Troop designs all actually contain the same thing and could, as a shortcut, be written on one card.

That said, I haven't gotten to programming yet but I've already seen a payoff from the cards in the form of an organizational hierarchy starting to form. I've got a list of seven classes that don't appear anywhere in the application, but will be great to add in as abstract parent classes. That is to say, I can make these classes with a set format but no data, and then make "child" or sub-classes that take that general structure and specialize it to their needs. It should also allow me to easily compare certain values.

As an example, a station could be built at any point of interest in a system, whether it's orbiting a planet, a moon, a star, or whatever else. Rather than having to store in the station's information both the name of the object it's stationed at and the type of object that is, by having all of these other objects (stars, planets, etc) as children classes to the overall Location parent class, I can simply have the station's location compared to anything that is a child of Location.

This will also work for fleets for current, and target, locations. As I said before, I haven't coded yet, so hopefully it'll work out half as well as I'm imagining it will, but it's nice to see things like this falling into place.

My plan, for the moment, is to develop the GUI class(es) next. I hope to have all of the GUI defined in one class, so that it can share a few easily-redefined variables, and then whenever I need a certain window I'll have the code handling that window call it from the list of already-created objects in the GUI. The intention is that when the user first starts the program, they'll be prompted with a login window where they enter their username and password, as well as being given either a list of display resolutions or a full-on configuration window (depending on how many things there actually are to configure). Personally, I'd like the application to run full-screen, but one of the options will most likely be a windowed mode. I did write up a little "Hello World!" fullscreen application, because I actually was doubtful that Java could even do that. It can, and therefore I intend to work with it.

When I say  I'm developing the GUI, I mean the bare minimums. Rather than dealing with test programs for all of my stuff, I'd like to just plug in the code to the GUI I'm actually going to be using. Formatting of that GUI can come later, since as far as the code is concerned, the button can be gray with the word "Exit" on it or it can be a picture of an open door, it's still the same object.

I have a lot of time tomorrow so definitely expect some preliminary work on the GUI to be done for my next post. I might even post screenshots, not that they'll be pretty.

No comments: