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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:26:32+00:00 2026-06-13T02:26:32+00:00

Background: I am currently working on a game, in which there will be several

  • 0

Background:
I am currently working on a game, in which there will be several types of furniture such as chairs, tables or paintings for the player to interact with. For this I have created an abstract class GameObject that handles everything all these objects will have in common (such as drawing, holding position variables etc.). The furniture pieces will have a few parameters that differs, such as width and height (integers) and also what happens when the user choose to interact with it (for example: chairs -> if player is close, sit down, tables -> nothing, paintings -> examine independent of distance). Furniture can be created from a menu, that returns some kind of identifier for the selected piece (currently an integer).

The Question:
How should I implement the different pieces of furniture?
One way would be to create a subclass for each piece of furniture. But this has two drawbacks; First it will be hard to manage that many classes, and secondly when the furniture is created, the correct subclass of GameObject will somehow have to be created based on the identifier (see the followup question).

The most logical option to me seems to be to create a general class that takes the width and height parameters in the constructor as well as a runnable/other interface that can be run when the user clicks on the object. The different values could possibly be stored in a database and retrieved based on the identifier, but the problem still arises with the different actions, since the Runnables cannot be stored externally, and that leads back to the same problem as solution 1; Many different classes where one has to be chosen for the current object.

Followup Question:
Depending on the types of furniture and actions it seems possible that more advanced subclasses with additional methods might be required. If so, the problem of choosing which one to implement depending on an identifier remains regardless of the solution to the previous question. I don’t want to use a gigantic switch statement to instantiate different classes, so is there any way around this?

The game is for the Android platform, but there might be future IOS port, so java-specific answers is not preferable, but acceptable.

  • 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-13T02:26:33+00:00Added an answer on June 13, 2026 at 2:26 am

    Its really tough to come up with a perfect design solution for the problem without considering all the if’s and but’s.

    However, one crucial part for your game is the relationship between the items (Furniture, painting, etc) and the actions that can be performed on each item. This is how you can model this relationship (Using composition ) :

    Action : Interface representing a game action. Contains a a single method called performAction.

    SittingAction : A concrete class that implements Action. Represents a game action for sitting. Implements the performAction method to define the code for performing the sitting action.

    ExamineAction : A concrete class that implements Action. Represents a game action for examining an item. Implements the performAction method to define the code for performing the examine action.

    Similarly, you can define one action per type of action that can be performed in your game.

    GameItem : A class representing an item in the game. Contains properties common to all items such as item name, breadth, width, depth, etc and getters and setters for these properties. GameItem ‘has-a’ instance variable of type Action and a constructor that takes an Action parameter to initialize the Action. GameItem also defines a method called onInteraction that you can call when the user interacts with a GameItem. This method will delegate the task of performing the Action associated with a GameItem by calling the performAction method on the Action instance variable. Therefore, any class that instantiate a GameItem must pass the appropriate Action to the GameItem constructor that represents the Action associated with the GameItem. When a user interacts with an item, just call the onIneraction method.

    GameController : A class that listens to user events and calls the onIneraction method on the GameItem that was interacted with.

    That’s it. Clean and simple. No need for any if else statements to check what action to perform on what item. Simpy instantiate all your GameItem instances with the appropriate Action instances and have your GameController that listen for user inputs call the onIneraction method on the GameItem that was interacted with.

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

Sidebar

Related Questions

I'm currently working on a css3 gradient background which works fine on Chrome but
I'm currently working on a project in which i need to play a background
Some background I'm currently working on a mobile site so I keep switching user
Some historic background: I'm currently working with Wowza and attempting to decode the AMFPackets
Background Currently, I am working on a Rails application. I have different products that
Background: I have been working on a platformer game written in C++ for a
I'm currently working with a textbox that has a background. I was wondering if
BACKGROUND: I'm currently working on building a photography gallery where I release a new
I am currently working on an Android tablet application which has two fragments, a
Some background info: I am working on an opengl game for fun/experience, and in

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.