|
|
|
|
|
by valuearb
3095 days ago
|
|
“But first of all, the OO inheritance here is irrelevant. The queen is the only piece which actually “inherits” properties from other pieces! We don't need an object model to simply reuse some functions to calculate legal moves given a position. Just a few global functions.” Don’t all pieces have a location? Aren’t all pieces movable? Might we want to display pieces? Do we want to journal them to files to save game state, or their moves to streams to play remotely? All of these things can be done procedurally, but they also fit nicely into an OO design. |
|
Make a table containing locations for each piece.
> Aren’t all pieces movable?
Make a function ("procedure") that moves a piece (e.g. edits the location table).
> Might we want to display pieces?
Make a render function (e.g. gets a piece type and a position)
> Do we want to journal them to files to save game state, or their moves to streams to play remotely?
Write serialization and deserialization routines (again, procedures that get piece type and position).
No need to cram that in to some idea of piece "class". That only glues things together that don't belong together. OO is pretty much crap.