Assigning static instances to non-static ones in Flyweight pattern?

A SoldierClient doesn't hold a copy of SOLDIER it holds a reference to SOLDIER and every SoldierClient holds a reference to the same SOLDIER Answering the edit Each soldier's location is held in SoldierClient instances ( currentLocationX and currentLocationY properties). The code comments for those properties spell it out as well: "this state is maintained by the client" (i.e. , "this state is not maintained in the SoldierImp instance") Everything is in moveSoldier s parameters: there's no SoldierImp instance state.

Think of it like a static utility method. Coordinates are provided by the SoldierClient instance; they're never stored by the SoldierImp just used.

A SoldierClient doesn't hold a copy of SOLDIER, it holds a reference to SOLDIER, and every SoldierClient holds a reference to the same SOLDIER. Answering the edit Each soldier's location is held in SoldierClient instances (currentLocationX and currentLocationY properties). The code comments for those properties spell it out as well: "this state is maintained by the client" (i.e.

, "this state is not maintained in the SoldierImp instance"). Everything is in moveSoldier's parameters: there's no SoldierImp instance state. Think of it like a static utility method.

Coordinates are provided by the SoldierClient instance; they're never stored by the SoldierImp--just used.

– coder9 Oct 18 at 16:40 @coder9 The code you link to never changes a property of the reference; in fact the reference has no properties. – Dᴀᴠᴇ Nᴇᴡᴛá´? É´ Oct 18 at 16:42 Question edited as above.

Thanks – coder9 Oct 18 at 18:30 @coder9 Moved response comments into my answer (which you should accept :p – Dᴀᴠᴇ Nᴇᴡᴛá´? É´ Oct 18 at 18:45 @coder9 Another way to figure it out is to just step through the code in a debugger a couple of times; sometimes it just takes seeing it "in action" before it ends up making sense :) – Dᴀᴠᴇ Nᴇᴡᴛá´? É´ Oct 18 at 19:24.

As the documentation mentions: The solution is to keep the common state of soldiers in a shared object Really every SolderClient has a reference to SOLDIER not a copy. In every SolderClient the variable Soldier soldier is referencig just to one object ant it is the same for all clients. Since Flyweight pattern uses a Singleton pattern maybe you can check it first: oodesign.com/singleton-pattern.html.

Each SoldierClient instance has a reference to a Soldier object. In this case they all point to the same instance. You'll notice that for each call to SoldierFactory, the same Soldier object is returned -- there is only one call Soldier's constructor.

See also Singleton.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions