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
Piececlass, with an internal array which determines the shape of the piece, versus having sevenPiececlasses, 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 eachBlockcontains its location on the Board (in graphical coordinates) vs. having a 4x4 array wherenullmeans there is no block there, and location is determined by the shape of the array. - Location: Each
Blockin thePiecearray or on theBoardarray stores its location vs. thePieceand theBoardknow the locations of theBlocksthat comprise them. - Generating a Piece: Have a static method of the Piece class
getRandomPiece, or have aPieceFactorywhich you make one instance of that has thegenRandomPiecemethod on the instance. - Manipulating the current piece: Use the
Proxypattern, so that everything that needs access to it just uses the proxy, or have agetCurrentPiecemethod on theBoardclass 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?