title: How to create an auto increment every time an object is created and decrements when it is "destroyed"
body: <p>When I create an instance of the class actor I add the object faction.</p>
  
  <pre><code>//Constructor
  Actor(String name, Race race, Faction faction){
      this.name = name;
      this.race = race;
      this.faction = faction;        
  }
  </code></pre>
  
  <p>I wanted that every time the object <strong>faction</strong> is used by the <strong>actor</strong> the an auto count inside the object faction increments, and every time the object <strong>actor</strong> is destroyed it decrements.</p>
  
  <pre><code>public class Faction {
  
  private String name;
  private int membersNum;
  private ArrayList&lt;Faction&gt; knowFactionList = new ArrayList&lt;Faction&gt;();
  private ArrayList&lt;Relation&gt; factionRelationList = new ArrayList&lt;Relation&gt;();
  
    Faction(String name){
          this.name = name;        
     }  
  
  
  
  public void addBattleMember(){
         membersNum++;
     }
     public void removeBattleMember(){
         membersNum--;
     }
  </code></pre>
  
  <p>I am now using this method inside the class Faction Manager to create the list and manually decreasing when the object actor stop being used.</p>
  
  <pre><code> public void buildActiveFactionsOnBattle(ArrayList&lt;Actor&gt; actorList) {
      for (Actor act : actorList) {
          act.getFaction().addBattleMember();
          if (!activeFactionsOnBattle.contains(act.getFaction()))
              activeFactionsOnBattle.add(act.getFaction());
      }
  }
  </code></pre>