I am stuck at trying to decide something in my class design. This is the overview of what I need to design:
- Robot that paints blocks on a square grid (a grid is collection of n blocks).
- Let's say there are 4 types of blocks in a grid and each block could cost different amount to paint.
- User will input command to instruct robot which block to paint.
- If block was already painted, there will be penalty to repaint it.
- Finally, report total cost (split by block types), and commands issued by the user.
Some of the things that I have modeled are as follows:
class Robot {
// get current location
// place it at given location
}
class Grid {
// Grid is a collection of blocks
Block[][] blocks;
}
class Block {
// each block has it's coordinates,
// has paint status (painted or unpainted),
// and accepts a visitor to determine price to paint
}
class SquareBlock extends Block {
}
class RectangularBlock extends Block {
}
For issuing commands, I modeled them as Command design pattern.
Question:
I am getting confused on is in which class should the visited (aka painted) blocks be stored (to handle #4 and #5 above)?
-
Should I store them in
Robot? (I didn't thing it belonged inRobotbecause it felt like tight coupling between the notion ofRobotandpaintable block.) -
I didn't want to store it in
Gridas well because, again, I don't think thatGridneeds to know what action is being taken on it (not too sure about this though). -
I could've stored in different class (say
Foo) but then I thought that may be user can issue a command likewhere ever Robot is, paint next 2 blocks. In this case, since this would be executed inPaintCommand(handled by CommandPattern),Foowouldn't know what blocks have been painted.
Please let me know your thoughts.
Aucun commentaire:
Enregistrer un commentaire