• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Examples of class variables

 
Ranch Hand
Posts: 424
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
Posts: 39348
755
Eclipse IDE VI Editor Java
  • 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: 64710
226
  • 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: 708
10
  • 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: 64710
226
  • 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!