From: Erik V. <eri...@hc...> - 2008-11-06 19:48:06
|
This is almost exactly the solution I have proposed in my discussion earlier this week with Brett. The difference is, that currentPhase is already available, so gameManager does not need to be prepended. > -----Original Message----- > From: Mark Smith [mailto:mar...@gm...] > Sent: Thursday 06 November 2008 02:16 > To: Development list for Rails: an 18xx game > Subject: Re: [Rails-devel] Starting on a client/server > > 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 > > > > -------------------------------------------------------------- > ----------- > 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 > |
From: Mark S. <mar...@gm...> - 2008-11-07 00:03:36
|
I can then agree with this change. What I feel would be beneficial is to find cases where you are running 'getInstance' and determine if there is a better way to do this. I feel the 'getInstance' routine is a bad idea in general, because it allows for the effective globalization of variables. |
From: Erik V. <eri...@hc...> - 2008-11-07 10:20:00
|
I consider a class "getInstance()" method to be a perfectly acceptable way to get access to the instance of a Singleton. Whether or not singletons are a good idea is a different discussion. In general I see no problems with it, except that in Rails we should get rid of most existing singletons if we want to aim for a multi-game server. However, I don't understand what you mean with "global variables" in this context. And I certainly don't see any connection between variables being global (or whatever) and the use of class getInstance methods. Puzzled, Erik. P.S. Thanks for finding and fixing the 1856 map display bug. Works fine for me. > -----Original Message----- > From: Mark Smith [mailto:mar...@gm...] > Sent: Friday 07 November 2008 01:04 > To: Development list for Rails: an 18xx game > Subject: Re: [Rails-devel] Starting on a client/server > > I can then agree with this change. > > What I feel would be beneficial is to find cases where you are running > 'getInstance' and determine if there is a better way to do this. I > feel the 'getInstance' routine is a bad idea in general, because it > allows for the effective globalization of variables. > > -------------------------------------------------------------- > ----------- > 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 > |
From: John A. T. <ja...@ja...> - 2008-11-07 15:55:57
|
Erik Vos wrote: > I consider a class "getInstance()" method to be a perfectly acceptable way > to get access to the instance of a Singleton. Whether or not singletons are > a good idea is a different discussion. In general I see no problems with it, > except that in Rails we should get rid of most existing singletons if we > want to aim for a multi-game server. > > However, I don't understand what you mean with "global variables" in this > context. And I certainly don't see any connection between variables being > global (or whatever) and the use of class getInstance methods. > > Puzzled, > The argument against singletons is that it makes testing hard, as you can't easily replace the underlying object with a mocked instance. The alternative is using dependency injection, such as Guice. Also see http://code.google.com/p/google-singleton-detector/wiki/WhySingletonsAreControversial (which is a Google project to help detect various kinds of global state). -- John A. Tamplin ja...@ja... 770/436-5387 HOME 4116 Manson Ave Smyrna, GA 30082-3723 |
From: Mark S. <mar...@gm...> - 2008-11-08 15:59:24
|
Why I see these singletons as effectively global variables is because the way you have it set up, where you can call (for example) the GameManager.getInstance () static routine from anywhere in the code base, allows for the GameManager class to be accessed and manipulated from anywhere. There is no true "encapsulation" enforced. The getInstance method allows any code to muck around with stuff it shouldn't know or care about. Mark |