title: Flyweight pattern vs static fields
body: <p>In my understanding the purpose of the flyweight pattern is to decrease memory footprint and increase performance by sharing common, extrinsic state. Why would anyone prefer to implement the pattern over storing the shared state in static fields?</p>
  
  <p>Consider the following example: <a href="http://www.oodesign.com/flyweight-pattern-wargame-example-java-sourcecode.html" rel="noreferrer">http://www.oodesign.com/flyweight-pattern-wargame-example-java-sourcecode.html</a></p>
  
  <p><img src="https://i.stack.imgur.com/lBDZe.png" alt="enter image description here"></p>
  
  <p>If I am right then the point in this example is to share the common state (soldierGraphicalRepresentation object) between all instances of the SoldierClient class by holding a reference to a single SoldierImp object.</p>
  
  <p>Why would I hassle with implementing this design? I would be tempted to declare the SoldierClient class as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class SoldierClient implements Soldier 
  {
      protected static Object soldierGraphicalRepresentation;
      private int currentLocationX;
      private int currentLocationY;
  
      static SoldierImp()
      {
          soldierGraphicalRepresentation = LoadGraphicalRepresentation();
      }
  
      public void moveSoldier(int previousLocationX, int previousLocationY, int newLocationX, int newLocationY) {
          // do stuff with the graphical representation
  
      }
  }
  </code></pre>
  
  <p>This way all instances of the SoilderClient share a reference to the same soldierGraphicalRepresentation object and the same goal is achieved. Am I wrong?</p>