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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:59:17+00:00 2026-05-26T05:59:17+00:00

I am writing a particle transport code. In this code physical objects implement an

  • 0

I am writing a particle transport code. In this code physical objects implement an interface Volume. One implementer of Volume is the case of interest for this code– the Particle class. In my design, Volumes contain other Volumes all the way down to the smallest Volume implementer, Particle. This will work great as long as Particles want to fly around unmonitored through volumes having interactions.

However, the moment I want to implement some sort of Particle detector Volume, which will record information about the Particle, I have a problem. The Volume interface doesn’t contain a way to get the special type of information a Particle has. If a Particle makes its way into the detector Volume, I will have to do something like check its type with reflection before I cast it to Particle from Volume and call the Particle methods. Generally (from what I have seen) this type of thing gets flagged with a “bad design” label.

I could make it so that only Particles can cross Volume boundaries in the Volume interface (tie the interface to the special case Particle), but I don’t really want to impose that limit on my code. It’s possible that I may want to allow volumes to move around and join later.

So does this sound like a bad design? Is there another obvious way to handle this problem? I will attach code if need be, but the general problem seems independent of my particulars (and fairly independent of language).

Thanks in advance. I really appreciate all the knowledge here on SO.

  • 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-26T05:59:17+00:00Added an answer on May 26, 2026 at 5:59 am

    From what I’ve read, dynamic casting is not considered terrible in Java. Simple type checking is much less extreme than using the full Reflection API.

    You can either attempt the dynamic cast and catch a possible ClassCastException, or do an isinstance Particle check before casting.

    Conceptually, it may make more sense for Particles to implement an interface that indicates they have the information your Particle detector wants to record. Without knowing more about your design we can’t say.

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

Sidebar

Related Questions

Writing a class, how do I implement foo.send(item) ? __iter__ allows iterating over the
Writing the code for the user authentication portion of a web site (including account
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
Writing documentation in html requires some code examples. What to do with characters that
Writing a python program, and I came up with this error while using the
I am currently writing a Particle System using XNA. What I'd like to do
I'm writing a particle system that uses point sprites in OpenGL ES 1.1 on
This is my little big question about containers, in particular, arrays. I am writing
Writing some docs with code snippets which I want to be copyable to run
Writing my first PHP Class and came across an issue, the following is my

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.