J
John Leonard
I'm starting a Chess program in Java. Actually, I started writing one in
qbasic back in '99 and I'd say I completed ~35% of a working version.
Anyhow, I'm just introducing myself to Java. Also, I have C experience but
no OOP experience. Without calling in to question my entire approach
(please), let me state my question:
1) Physical objects, such as pieces, squares and so on, should be
represented by classes. Never mind for the moment how actions, such as
moves, should be represented.
2) Although in time it might prove unnecessary, I have, for the moment,
created a location class. As I said, I'm new to Java and although I think
that the basic properties of the location class probably exist is some
predefined class, perhaps with a name like "point", I don't know where to
find it yet. So I have this class called "location" whose job is to hold
rank and file (x, y) information for squares and pieces.
3) The location class will have one or more constructors, one of which will
take rank and file values from the calling procedure and assign these to its
internal members. Of course, it will have to examine these values and make
sure that they are within the range 0 to 7 (or 1 to 8).
4) My question (finally) is this: what do I do if these values are not
within the correct range? Do I throw an Exception? In this case, the
constructor would be called within a try block and the exception caught
within the catch block that follows. Is this a correct way to use the
Exception mechanism?
John Leonard
qbasic back in '99 and I'd say I completed ~35% of a working version.
Anyhow, I'm just introducing myself to Java. Also, I have C experience but
no OOP experience. Without calling in to question my entire approach
(please), let me state my question:
1) Physical objects, such as pieces, squares and so on, should be
represented by classes. Never mind for the moment how actions, such as
moves, should be represented.
2) Although in time it might prove unnecessary, I have, for the moment,
created a location class. As I said, I'm new to Java and although I think
that the basic properties of the location class probably exist is some
predefined class, perhaps with a name like "point", I don't know where to
find it yet. So I have this class called "location" whose job is to hold
rank and file (x, y) information for squares and pieces.
3) The location class will have one or more constructors, one of which will
take rank and file values from the calling procedure and assign these to its
internal members. Of course, it will have to examine these values and make
sure that they are within the range 0 to 7 (or 1 to 8).
4) My question (finally) is this: what do I do if these values are not
within the correct range? Do I throw an Exception? In this case, the
constructor would be called within a try block and the exception caught
within the catch block that follows. Is this a correct way to use the
Exception mechanism?
John Leonard