• Post Reply Bookmark Topic Watch Topic
  • New Topic

Examples of class variables  RSS feed

 
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

would a players score in a game or a players money in a casino typically be a static variable? just wondered if that was typically used in a scenario like this
can you give me any other practical examples?

thanks
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The casino's money could be static. I wouldn't think the player's money/score would be static because there are presumably many players. So I'd expect a Player object for each one. An ArrayList of all the known Player objects would makes sense as static though.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:The casino's money could be static. . . .
But making that field static would mean you can only program the app to model one casino in the whole universe.
 
Bartender
Posts: 572
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many casinos around the world, so I would have a Casino class.
Each instance of Casino would have many instances of CasinoGame, an abstract class.
There would be subclasses of CasinoGame: Blackjack, Poker, Roulette, etc.
Each casino would also have many instances of registered Player.
Each game would also have possibly many instances of Player, each of which must come from that casino's list of Players..

None of those classes would have any static variables.
 
Greenhorn
Posts: 24
4
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One possible value I could think of as being static might be a 'banned player list'. As is usual in somewhere like Vegas, if a player is banned from one casino, they are blacklisted from other casino's in the same area.

But then this [possibly] wouldn't apply to casino's outside the area. It depends on what your problem domain relating to casino's is?

L.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L Hasan wrote:One possible value I could think of as being static might be a 'banned player list'. . . .
Nice idea Pubs use the same sort of banned list.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!