Android - Global Object Archetypes - Best Approach?
<p>I have the following class for use as a template:</p>

<pre><code>public class BasicWeapon {
 private String name; 
 private int type; 
 private int power; 
 private int energy; 
 private int accuracy;

  public BasicWeapon(String createName, int createType, 
       int createPower, int createEnergy, int createAccuracy) {
      name = createName; 
      type = createType; 
      power = createPower; 
      energy = createEnergy; 
      accuracy = createAccuracy; 
   } 
</code></pre>

<p>and I want to create just ONE set of each of the basic weapons in the game. Each actual weapon in the game will consist of:</p>

<pre><code>public class Weapon {
  private BasicWeapon baseWeapon; 
  private String name; 
  private int tinkerPower; 
  private int tinkerEnergy; 
  private int tinkerAccuracy;

  public Weapon() { 
    baseWeapon = MyApp.globalBasicWeapons[EMPTY_WEAPON]; 
    name = MyApp.globalBasicWeapons[EMPTY_WEAPON].getName(); 
    resetTinkering(); 
   } 
</code></pre>

<p>This struck me as being the best way to go about it. I only need to create and store one instance of the basic weapon, and each instance of actual weapons only stores the tinkering that is unique to it. In order to only create one instance of each, though, I was made to understand that I should extend the Application class, like so:</p>

<pre><code>public class MyApp extends Application {

  public static final int NUM_BASICWEAPONS = 1; 
  public static final int EMPTY_WEAPON = 0;
  private BasicWeapon[] globalBasicWeapons;

  public MyApp() { 
       super(); 
       globalBasicWeapons = new BasicWeapon[NUM_BASICWEAPONS];
       globalBasicWeapons[EMPTY_WEAPON] = new BasicWeapon("Empty", 0, 0, 0, 0); 
   }
</code></pre>

<p>Unfortunately, it turns out that you can only use <code>((MyApp) getApplication())</code> from within an activity, so I can't refer to the basic weapon types that are parts of the <code>MyApp</code> object directly from my Weapon class, nor can I use the phrase <code>EMPTY_WEAPON</code>.</p>

<p>What's the best way to handle these weapon archetypes? Do I need to change the Weapon constructor to accept a BasicWeapon as a variable, and just accept the fact that my activities will need to be responsible for passing them on? How can I make <code>EMPTY_WEAPON</code> and <code>NUM_BASICWEAPONS</code> available in my other classes without defining them in each and every one? Am I going about this in completely the wrong way?</p>

<p>Clearly, I'm a newbie. This project started as one of those “Wouldn't it be cool...” conversations, and I got nominated to try coding as the computer nerd of our circle of friends. I'm trying to teach myself Java and Android as I go here.</p>

<p>(I apologize for the lack of formatting... I'm not sure how to make those nice little code blocks)</p>
