From: Mark S. <mar...@gm...> - 2008-11-06 00:10:48
|
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 On Wed, Nov 5, 2008 at 3:59 PM, Erik Vos <eri...@hc...> wrote: > Mark, > > I'm not sure if I understand your point. > In GameManager, getInstance() is a static method, but getCurrentPhase() is > not. > Your shortened call wouldn't compile. > > Generally spoken, there might indeed be a lot of unwieldy code around. > The code base has grown in ways that may have caused inconsistencies and > redundant code (we have just seen an example - I'm going to fix it soon), > unused or almost duplicate methods etc. When I find such a case, I often try > to fix it, but not always is the solution immediately clear and other > priorities may cause it being forgotten. So it goes. Over time all will be > done (I hope). > > Erik. > > >> -----Original Message----- >> From: Mark Smith [mailto:mar...@gm...] >> Sent: Wednesday 05 November 2008 01:43 >> To: Development list for Rails: an 18xx game >> Subject: Re: [Rails-devel] Starting on a client/server >> >> I would like to pose a question using your example routine in >> the Tile Class: >> >> 325 /** >> 326 * Is the tile layable now (in the current phase)? >> 327 * >> 328 * @return >> 329 */ >> 330 public boolean isLayableNow() { >> 331 return >> GameManager.getInstance().getCurrentPhase().isTileColourAllowe >> d(colourName); >> 332 } >> >> This calls in the Game Manager the 'getInstance ()' routine: >> >> 336 /** >> 337 * @return instance of GameManager >> 338 */ >> 339 public static GameManager getInstance() { >> 340 return instance; >> 341 } >> >> What I am very puzzled by is why bother to call to get the >> instance at all? >> If you have the GameManager, you already have a copy of the instance. >> You can reduce the original call to: >> >> 325 /** >> 326 * Is the tile layable now (in the current phase)? >> 327 * >> 328 * @return >> 329 */ >> 330 public boolean isLayableNow() { >> 331 return >> GameManager.getCurrentPhase().isTileColourAllowed(colourName); >> 332 } >> >> And even saving the a pointer to the object within the object is a >> circular reference that accomplishes nothing useful that I can see. >> >> Maybe I am failing to realize why you bother with this >> self-referencing object. >> >> Mark >> >> -------------------------------------------------------------- >> ----------- >> This SF.Net email is sponsored by the Moblin Your Move >> Developer's challenge >> Build the coolest Linux based applications with Moblin SDK & >> win great prizes >> Grand prize is a trip for two to an Open Source event >> anywhere in the world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> Rails-devel mailing list >> Rai...@li... >> https://lists.sourceforge.net/lists/listinfo/rails-devel >> > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Rails-devel mailing list > Rai...@li... > https://lists.sourceforge.net/lists/listinfo/rails-devel > |