Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:19:13+00:00 2026-05-26T06:19:13+00:00

I was going through the Flyweight sample code at http://www.oodesign.com/flyweight-pattern-wargame-example-java-sourcecode.html and wondering how it

  • 0

I was going through the Flyweight sample code at http://www.oodesign.com/flyweight-pattern-wargame-example-java-sourcecode.html and wondering how it really works when we assign a static instance (SOLDIER as in the above site) to a non-static soldier instance in SoldierClient do we really reduce the object size since each SoldierClient will somehow hold a copy of SOLDIER instance in each SoldierClient object we create?

EDIT:

In the method moveSoldier()
it says

// delete soldier representation from previous location
// then render soldier representation in new location

How come this doesn’t affect all the objects created in class WarGame

package flyweight;

public class SoldierImp implements Soldier {

    /**
     * Intrinsic State maintained by flyweight implementation
     * Solider Shape ( graphical represetation)
     * how to display the soldier is up to the flyweight implementation
     */
    private Object soldierGraphicalRepresentation;

    /**
     * Note that this method accepts soldier location 
     * Soldier Location is Extrinsic and no reference to previous location 
     * or new location is maintained inside the flyweight implementation
     */
    public void moveSoldier(int previousLocationX, int previousLocationY,
            int newLocationX, int newLocationY) {

        // delete soldier representation from previous location 
        // then render soldier representation in new location   
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:19:14+00:00Added an answer on May 26, 2026 at 6:19 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was going through this: http://code.google.com/apis/webfonts/ (Which BTW I think is fantastic) And was
After going through the article at http://geekexplains.blogspot.com/2008/06/diff-between-externalizable-and.html , i got to know Externalizable is
Just going through the sample Scala code on Scala website, but encountered an annoying
im going through the setup on http://www.railstutorial.org/chapters/static-pages#fig:autotest_green and im stuck on this particular error:
Going through the tutorial here: http://www.asp.net/mvc/tutorials/iteration-4-make-the-application-loosely-coupled-cs I've noticed that they are passing the EF
When going through some sample code, notice that setting the main Window Title in
After going through so many documents and online content like: http://stackoverflow.com/questions/4066167/sencha-touch-or-jquery-mobile http://stackoverflow.com/questions/5093691/sencha-touch-vs-jqtouch-vs-gwt-mobile-vs-xui-vs-jquery-mobile-vs http://www.quora.com/Were-deciding-between-jQuery-Mobile-currently-in-alpha-and-Sencha-Touch-What-are-the-pros-and-cons-for-each http://interfacethis.com/2011/adventures-in-html5-part-one/
Going through the php.net site, it had an example for header, which says would
while going through some of the mili source code I came across a struct
After going through Marshall code snippet Got the Idea that marshalling is used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.