You are writing a Tetris program in Java. How would you set up your class design with regards to the following aspects?
- Piece class: Have one
Piece
class, with an internal array which determines the shape of the piece, versus having sevenPiece
classes, one for each of the pieces. They are all subclasses of one generic Piece class. - Piece class representation: Have an array of 4 instances of
Block
, representing one square of a piece, and eachBlock
contains its location on the Board (in graphical coordinates) vs. having a 4x4 array wherenull
means there is no block there, and location is determined by the shape of the array. - Location: Each
Block
in thePiece
array or on theBoard
array stores its location vs. thePiece
and theBoard
know the locations of theBlocks
that comprise them. - Generating a Piece: Have a static method of the Piece class
getRandomPiece
, or have aPieceFactory
which you make one instance of that has thegenRandomPiece
method on the instance. - Manipulating the current piece: Use the
Proxy
pattern, so that everything that needs access to it just uses the proxy, or have agetCurrentPiece
method on theBoard
class and call that any time you want to do something with the current piece.
This is not homework. I'm just at odds with what the intro CS course teaches at my college and I want to see what people in general believe. What would be thought of as "good" OOP design? Ignore the fact that it's for an intro course - how would you do it?