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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:33:23+00:00 2026-05-30T21:33:23+00:00

In the game engine I work with (Unity), a base class for every game

  • 0

In the game engine I work with (Unity), a base class for every game object has a method ‘SendMessage(“methodName”)’, which invokes specified method in every class of every object that is associated with it — if it has one.

Should I create a new interface with method “methodName” for every message that I can send that way to formalize this interaction, or will it be just additional work without any gain? It seems like a good thing to do, because that way I will be able to see what messages this class can receive from it’s declaration, but I can’t see what errors, for example, I can help avoid with this. And I didn’t see it used that way either — so may be it’ll just be a wasted effort after all.

  • 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-30T21:33:25+00:00Added an answer on May 30, 2026 at 9:33 pm

    Strict answer: YES, use interfaces! Real life answer: it may depend.
    In general to use strings in such way is dangerous (What if method declaration will change? What if you type the method name in a wrong way? Do you have any security issue with it?). The answer to these questions is always: you’ll catch that problems at run-time instead of compile -time (and it means you may release something that doesn’t work even if it’s a kind of error that SHOULD BE found at compile-time). Moreover do not forget performances, using strings you have to use Reflection (I guess/hope you won’t have a big switch/case statement).
    To write interfaces is tedious but 99% of times is the best way to keep your code clean and easy to maintain.
    That said you MAY need to use that strings to invoke methods (I’m thinking, for example, about Java Agents or some kind of “dynamic” instantiation based on configuration or on messages content).
    So I guess the right answer is IT DEPENDS. I think you should always use interfaces because of speed, error checking, maintenance and security issues (where applicable). SOMETIMES you may need to use textual messages but you should use them carefully and never because you’ll write less code (this is NEVER a good reason to choose one approach instead of another).

    Addendum: with interfaces you may use a “services daemon” mechanism (based for example on IServiceProvider) to discover all bojects that implement a specific interface. Achieve the same thing using SendMessage() may be tricky (will you use a CanHandlMessage() method?) and error-prone because of duplication.

    Example:
    This is just an example (to explain what I mean with “service daemon”, see the function FindServices() which retrieve all objects that implements a given interface), I guess you wouldn’t use LINQ and enumerables in your high speed game. I think it’s much easy to understand than a SendMessage() with parameters and moreover it’s easy to update.

    interface IEnemy
    {
     Point3D Position
     {
      get;
      set;
     }
    
     void Destroy();
    }
    
    void FireBomb(Bomb bomb, Point3D impactLocation)
    {
     IEnumerable<IEnemy> affectedEnemies = 
      FindServices<IEnemy>.Where(x.Location - impactLocation <= bomb.BlastedArea);
    
     Execute(affectedEnemies, x => x.Destroy());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If have I have a game engine that has multiple threads that all work
Okay, so i am continuing to work on my little game engine to teach
Its a little strange. Ok so I am working with OGRE game engine which
I realize that Unity is a game engine and XNA is just a framework,
i want to create a basic game Draw engine class for my 2D game.
I've got a game engine where I'm splitting off the physics simulation from the
I have my own game engine using C++ and OpenGL, but I have models
I have a game engine that uses OpenGL for display. I coded a small
I'm making a game engine for mobile devices. I want to compile my code,
I'm working on a simple 2D game engine in Java, and having no trouble

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.