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

  • Home
  • SEARCH
  • 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 182381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:55:46+00:00 2026-05-11T14:55:46+00:00

I’m rather new to Java. After just reading some info on path finding, I

  • 0

I’m rather new to Java. After just reading some info on path finding, I read about using an empty class as an ‘interface‘, for an unknown object type.

I’m developing a game in Java based on hospital theme. So far, the user can build a reception desk and a GP’s office. They are two different types of object, one is a Building and one is a ReceptionDesk. (In my class structure.)

My class structure is this:

GridObject-->Building GridObject-->Item-->usableItem-->ReceptionDesk. 

The problem comes when the usable item can be rotated and the building cannot. The mouse click event is on the grid, so calls the same method. The GP’s office is a Building and the reception desk is a ReceptionDesk. Only the ReceptionDesk has the method rotate. When right clicking on the grid, if in building mode, I have to use this ‘if’ statement:

if (currentBuilding.getClass.equals(ReceptionDesk.getClass) 

I then have to create a new ReceptionDesk, use the rotate method, and the put that reception desk back into the currentBuilding GridObject.

I’m not sure if I’m explaining myself very well with this question. Sorry. I am still quite new to Java. I will try to answer any questions and I can post more code snippits if need be. I didn’t know that there might be a way around the issue of not knowing the class of the object, however I may also be going about it the wrong way.

I hadn’t planned on looking into this until I saw how fast and helpful the replies on this site were! 🙂

Thanks in advance.

Rel

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T14:55:47+00:00Added an answer on May 11, 2026 at 2:55 pm

    You don’t want to check the class of an object before doing something with it in your case. You should be using polymorphism. You want to have the Interface define some methods. Each class implement those methods. Refer to the object by its interface, and have the individual implementations of those objects return their values to the caller.

    If you describe a few more of the objects you think you need, people here will have opinions on how you should lay them out. But from what you’ve provided, you may want a ‘Building’ interface that defines some general methods. You may also want a ‘UsableItem’ interface or something more generic. Hospital could be a class that implements building. ReceptionDesk could implement UsableItem. Building could have a grid of UsableItem inside it.

    If rotate() was a common method to all furniture that actually did some work, you may consider making an AbstractUsableItem class that was an abstract class implementing UsableItemand providing the rotate() method. If rotate was different in each implementing class, you would have that method in the interface, but each class, like ReceptionDesk would do its own thing with the rotate() method. Your code would do something like:

    UsableItem desk = new ReceptionDesk(); desk.rotate() 

    In your example, if your mouse click on a screen rotated the object under it, and you really did need to check to see if the object could be rotated before doing something like that, you’d do

    if (clickedObject instanceOf UsableItem) {   ((UsableItem) clickedObject).rotate(); } 

    where UsableItem was the interface or abstract class. Some people feel that all design should be done via an interface contract and suggest an interface for every type of class, but I don’t know if you have to go that far.

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

Sidebar

Ask A Question

Stats

  • Questions 196k
  • Answers 196k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Subclassing listboxes in S60 (Avkon) is a major pain. I've… May 12, 2026 at 7:08 pm
  • Editorial Team
    Editorial Team added an answer One thing that I did wrong when playing around with… May 12, 2026 at 7:08 pm
  • Editorial Team
    Editorial Team added an answer It's not super easy to do exactly what you want,… May 12, 2026 at 7:08 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.