How best to manage "global" data - Static Class?

Discussion in 'Java' started by Chu, Apr 14, 2005.

  1. Chu

    Chu Guest

    I've got a small problem I want to get some input on. I'm trying to
    determine the best way to access a set of values. I've decided that I
    should do it as either a Static class or as an actual object that I can
    pass into each object. Let me attempt to describe the scenario:

    During a battle, each player will be in control of X units. Each unit
    has a set of values, such as Hitpoints, Shield Points, etc.

    G-Man has 10 units. Chu has 10 units and Apep has 10 units.

    Chu and Apep both attack G-man. The battle scenario runs Chu's attack
    first, then Apep. Both players are attacking the same units belonging
    to G-man so those Unit values need to somehow be shared between each of
    the "attack objects" belonging to Apep and Chu. What's the best way to
    share those unit values?

    1- Make a Units class that pre-loads every unit object, then pass a
    reference to that object into each of the attack objects and every
    other object that uses it?

    or

    2- Use a static class that pre-loads each unit object, then have each
    attack object simply reference the static unit class?


    Suggestions? Pro's/con's of each method?

    Thanks in advance.

    Ry/Chu
    Chu, Apr 14, 2005
    #1
    1. Advertising

  2. Chu

    steepyirl Guest

    Well, since the units in question belong to "G-man", they're not really
    global, are they? What if there is another player in the game who also
    has such units?
    You should probably just expose the units using getter/setter methods
    in the "Player" object - that way anyone else can access them.
    steepyirl, Apr 14, 2005
    #2
    1. Advertising

  3. Chu

    Chu Guest

    This particular piece of the program doesn't care who the owner is.
    This is the logic part that goes through and processes each turn. All
    it cares is that "group of X units" attacks "group of Y units."
    Chu, Apr 15, 2005
    #3
  4. Chu

    knightowl Guest


    > Chu and Apep both attack G-man. The battle scenario runs Chu's attack
    > first, then Apep. Both players are attacking the same units belonging
    > to G-man so those Unit values need to somehow be shared between each

    of
    > the "attack objects" belonging to Apep and Chu. What's the best way

    to
    > share those unit values?


    Actually the values of Chu and Apep do not need to be shared, or
    collected. As the battle insues setter and getter methods can be used.
    Moreover a hit method could be developed that is used in an interface
    for all the battle objects. As it gets hit it's points far based on
    sheild, and other attributes. When the object is dead it can return
    false to the attacker attack method.

    Bottomline, this does not need to be global. Each object should manage
    it's own attack, and dammage points.

    HFC
    knightowl, Apr 15, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wh
    Replies:
    0
    Views:
    274
  2. Robin
    Replies:
    0
    Views:
    404
    Robin
    Jun 6, 2007
  3. teo
    Replies:
    3
    Views:
    868
  4. nguillot
    Replies:
    0
    Views:
    424
    nguillot
    Apr 11, 2008
  5. How to manage static buffers

    , May 11, 2012, in forum: C Programming
    Replies:
    2
    Views:
    396
    James Kuyper
    May 15, 2012
Loading...

Share This Page