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 8265451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:48:31+00:00 2026-06-08T04:48:31+00:00

Currently I am designing a Monopoly game using Java. Each player in the game

  • 0

Currently I am designing a Monopoly game using Java.

Each player in the game can own different properties. The issue I’m having is how to assign different property objects to each player. I have both a Player class and a Properties class. Would composition be the best way to go about doing this? If so, how would I do it?

  • 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-06-08T04:48:33+00:00Added an answer on June 8, 2026 at 4:48 am

    I would add a new class PropertyManager.

    This allows you to easily provide business rules in a single location (good separation of concerns) rather than having to dive through a bunch of player or property objects if you opt for composition in either. This will keep the Player and or Property classes from becoming weighed down with buying/selling business rules in the future.

    public final class PropertyManager {
    
      /**
       * The PropertyManager instance, example usage:
       *   PropertyManager.INSTANCE.buyProperty(property, buyer);
       * NB: Good candidate for dependency injection instead if you are doing this.
       */
      public static final PropertyManager INSTANCE = new PropertyManager();
    
      private static final Map<Property, Player> propertyListing = new HashMap<Property, Player>();
    
      /**
       * Buy a property from the banker, banker or property manager could maintain
       * Collection of available properties
       */
      public void buyProperty(Player buyer, Property property) {
        if (propertyListing.containsKey(property)) {
          throw new IllegalStateException("Unable to buy unless owner sells it");
        }
        propertyListing.put(property, buyer);
      }
    
      /**
       * Broker a transaction between two players for the sale of a property
       */
      public void sellProperty(Player seller, Player buyer, Property property) {
        if (!propertyListing.containsKey(property)) {
          throw new IllegalStateException("Unable to sell Property which is not owned");
        }
        Player owner = propertyListing.get(property);
        if (!owner.equals(seller)) {
          throw new IllegalStateException("Unable to sell property seller doesn't own");
        }
        // TODO : Deduct/transfer monies (ensure sufficient value in buyer account etc)
        propertyListing.put(property, buyer); 
      }
    
      /**
       * Retrieve a List of all of the Player's properties
       */
      public List<Property> getProperties(Player owner) {
        // TODO Either iterate through the propertyListing or use a second Map for player to List<Property>, NB: they should be guarded with a shared lock if you do this (threading).
      }
    
      /**
       * Retrieve the owner of a Property or null if it is unowned
       */
      @Nullable // javax annotation indiciates can be null
      public Player getOwner(Property property) {
        return propertyListing.get(property);
      }
    
      /**
       * Hide the constructor as the only property manager should be INSTANCE
       */
      private PropertyManager() {
        // Prevent further instantiation
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently designing a web application using php, javascript, and MySQL. I'm considering two
I'm designing a Monopoly game while also reading up more on OO principles. I
I'm currently designing a system that requires an admin to log in using a
I'm currently designing a object structure for a game, and the most natural organization
I am currently designing an RTS Game in XNA. So far I have a
i am currently designing a ebook reader app as my project, i am having
I'm currently designing my first ever GUI for Windows. I'm using MFC and Visual
We are currently designing a GIS intranet application using GWT and ESRI ArcGIS. We
I'm currently designing solution where the domain model & the repository can be extended
We are currently designing a system using WPF which will communicate with other systems

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.