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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:36:34+00:00 2026-05-23T02:36:34+00:00

One often reads how it’s worth designing your code to avoid needing to make

  • 0

One often reads how it’s worth designing your code to avoid needing to make casts, and how finding yourself needing to cast might suggest that there is a better implementation available. I’m trying to achieve this holy grail of “cast-free code” in the implementation of a virtual world engine, where many objects have a wide variety of interfaces, acting as mediators and data (and sometimes as both) of many different forms. As one answer in a similar question mentions (Linkage), the aim is to always have a reference/pointer of the correct type at the required location rather than trying to dig one out from a large range of candidate objects.

My latest stab at managing this large issue involves registration of objects with their mediators which has some nice advantages in terms granularity of control (you can runtime configure many to many mappings between mediators and their targets).

There are some problems as well… The biggest I’m looking at at the moment is the de-registration of targets from mediators. In order to keep track of who’s using what without having to poll every possible mediator the program needs to store yet more data on what links have been created. On the one hand it would be possible for mediators to disconnect themselves simply by checking if their targets are expired (i’m using smart pointers and weak pointers for everything so this is not difficult), however this simply handles the expiry of objects and does not establish a framework for meaningful reconfiguration of behaviour.

When looked at from far away, it’s just another case of software boiling down to the trade-off between time and memory. Store more data to do less computation.

I want to ask what your thoughts are about structuring programs to avoid dynamic casts, and if you could share any strategies / patterns that are effective in these situations.

  • 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-23T02:36:34+00:00Added an answer on May 23, 2026 at 2:36 am

    This is a fundamentally flawed proposition. dynamic_cast exists for a reason. Trying to aim for cast-less code is just naive- casts serve a purpose. Sure, it might be the best thing to reduce them wherever you can, but that’s very different from trying to ban them. Code without dynamic_cast isn’t some kind of holy grail- either it doesn’t need it, in which case it’s just code, or it does need it, in which case it’s suboptimal code.

    However, to stay a little more on-topic, I personally find that just by not spreading inheritance around like it’s the Plague and I’m trying to cause the Apocalypse, then the need for casting is limited- templates are a miracle here.

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

Sidebar

Related Questions

Quite often one has to encode an big (e.g. 128 or 160 bits) number
One of the problems I often run into, is that I will include '
One thing I've started doing more often recently is retrieving some data at the
I often run into the problem that I have one stream full of data
One problem I have with open-source is not often the product or documentation, but
Often, one needs several enumerated types together. Sometimes, one has a name clash. Two
Often while editing config files, I'll open one with vi and then when I
How does one design loosely-coupled systems which may often require data from each-other but
The problem: I often have to update two or more repositories: One for the
I seem to often find myself wanting to store data of more than one

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.