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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:23:49+00:00 2026-06-06T06:23:49+00:00

I hope I can explain this problem right, it’s a bit confusing for me.

  • 0

I hope I can explain this problem right, it’s a bit confusing for me.

I have been working on a game library similar to flixel but, using C#’s XNA framework instead of Flash. Right now the current class layout is something like this.

ClxBasic -> ClxObject -> ClxSprite

Each class has a constructor and calls the constructor for the class below it. I use this code to do this.

namespace Test
{
    public class ClxBasic
    {
        public ClxBasic()
        {
            Constructor();
        }

        public void Constructor()
        {
            DoSomething();
        }
    }

    public class ClxObject : ClxBasic
    {
        public ClxObject() : base()
        {
            Constructor();
        }
            public void Constructor()
            {
                    DoSomething();
            }
    }

    public class ClxSprite : ClxObject
    {
        public ClxSprite() : base()
        {
            Constructor();
        }
            public void Constructor()
            {
                    DoSomething();
            }
    }
}

So basically when I create a new ClxSprite it calls the ClxSprite constructor, then all the ones below it (ClxObject and ClxBasic).

I’m sure there is an easier way to do this and I am all ears.

However, my bigger issue is actually how to properly derive and override methods from the other classes.

The issue is that when creating a class that extends from ClxSprite, for example, when calling a method that was overridden from the most basic class (ClxBasic), it will only call the bottom method and not the top.

The reason I need to do this is because I have a global class which keeps control of all the objects derived from ClxBasic by adding themselves to a list in the ClxBasic constructor.

Here’s some example code.

namespace Test
{
    public static class ClxG()
    {
        public static List<ClxBasic> GlobalObjects; //All objects will be added here by the ClxBasic constructor
            ClxSprite test = new ClxSprite();
            GlobalObjects.Add(test);
        public static Update()
        {
            foreach(ClxBasic basic in GlobalObjects)
                basic.Update(); //Calling this calls ClxBasic.Update() when it should call ClxSprite.Update()
        }
    }
}

When calling basic.Update() it goes to the bottom Update, the one located in ClxBasic, despite the object being a ClxObject or ClxSprite or other derived class.

I have a limited fix as well, by changing the ClxBasic to ClxSprite in the foreach loop, you can call that classes constructor method properly. However, when making custom classes based off of the library who override a method, the lower Update is called.

However, the limit is that you can’t add classes I didn’t specifically plan for. For example, if I were to derive a class Player from ClxSprite and, override the Update() method, it would get added to the GlobalObjects list but, never have it’s update called, the highest it will go is ClxSprite’s.

The way I want it to work is, in Game1.cs I want to just be able to put FlxG.Update() in the Game.Update() loop and just be able to create the object and have my framework handle the rest.

I hope I’ve made a bit of sense, the whole thing feels like some sort of inheritance inception and kind of makes my brain hurt.

  • 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-06T06:23:53+00:00Added an answer on June 6, 2026 at 6:23 am

    To also call a base class method as part of a child class implementation, you’d do this:

    class Base {
      public virtual void Method() {
        // ...
      }
    }
    
    class Derived : Base {
      public override void Method() {
        base.Method();
        // ....
      }
    }
    
    class Derived2 : Derived {
      public override void Method() {
        base.Method();
        // ....
      }
    }
    

    But the child method is not required to call the base one.

    Constructors, on the other hand, are always required to (ultimately) call a base constructor.

    Now, if you want a base class method to always be called as part of some processing, you can employ the template method pattern. Basically your base class has a non-virtual method that drives an algorithm that calls virtual (or abstract) methods; which the child classes can override to create their own versions.

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

Sidebar

Related Questions

I hope I can explain this right I have two input fields that require
This is in my opinion an abstract problem and I hope I can explain
Hello I hope someone can explain this problem. This is the code: class Memory{
Well guys, this problem just baffles me. I hope someone can explain to me
Hiim fairly new to vb so i hope i explain this right, the problem
I hope I can explain this problem decently well! I'm trying to implement a
I hope I can explain this well enough so that you can understand the
I hope I can explain this properly. I'm using flashDevelop for an avatar creation
I hope this I can explain what I am trying to achieve: I want
I hope I can explain my problem in a way that it's clear for

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.