From: Mark S. <mar...@gm...> - 2008-11-06 01:15:49
|
If this makes sense... then OperatingRound.java class, layTile routine could be changed from: 323 if (!tile.isLayableNow()) { 324 errMsg = 325 LocalText.getText("TileNotYetAvailable", 326 tile.getExternalId()); 327 break; 328 } to 323 if (!gameManager.getCurrentPhase().isTileColourAllowed (tile.getColourName())) { 324 errMsg = 325 LocalText.getText("TileNotYetAvailable", 326 tile.getExternalId()); 327 break; 328 } This would allow the isLayableNow routine to be tossed... and have the Operating Round which knows about the gameManager to perform the check. I have applied this change to my copy of the code, it compiles without error. And I then tossed the isLayableNow routine out, and the abstract reference in Tile as well. Mark On Wed, Nov 5, 2008 at 7:10 PM, Mark Smith <mar...@gm...> wrote: > Hmm... I believe I understand now why my "code-reduction" would not > work. I have seen cases where you store the instance of an object > within the object as a static variable, and have a static method to > return the instance. I generally avoid writing code that depends on > global variables, and this is one example. If I need a variable down > in a routine, I attempt to pass it in so there is no ambiguity. > > For this example I would have the routine that calls 'isLayableNow' to > instead get the tile colour from the Tile Class, then have the Phase > Class be called asking 'isTileColorAllowed' instead. > > You might still have a similar problem of finding the current phase by > whatever routine is currently calling 'isLayableNow' but it would need > to be examined. Searching for the use of this routine I find one use > in 'OperatingRound' class, LayTile routine. And it seems to be just a > double-check that it did not get selected by mistake, only an error > message is produced if it is true. > > Mark > |