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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:11:45+00:00 2026-06-07T01:11:45+00:00

By way of an intro, I’m creating a basic Quadtree engine for personal learning

  • 0

By way of an intro, I’m creating a basic Quadtree engine for personal learning purposes. I’m wanting this engine to have the capability of working with many different types of shapes (at the moment I’m going with circles and squares) that will all move around in a window and perform some sort of action when collision occurs.

After asking a question on the topic of generic lists earlier, I have decided on using an interface for polymorphism. The best interface for this would be an interface utilising Vector2 due to the fact that every object that appears in my Quadtree will have an x,y position and Vector2 covers that nicely. Here is my code as it currently stands:

public interface ISpatialNode {
    Vector2 position { get; set; }
}

public class QShape {
    public string colour { get; set; }
}

public class QCircle : QShape, ISpatialNode {
    public int radius;
    public Vector2 position {
        get { return position; }
        set { position = value; }
    }
    public QCircle(int theRadius, float theX, float theY, string theColour) {
        this.radius = theRadius;
        this.position = new Vector2(theX, theY);
        this.colour = theColour;
    }
}

public class QSquare : QShape, ISpatialNode {
    public int sideLength;
    public Vector2 position {
        get { return position; }
        set { position = value; }
    }
    public QSquare(int theSideLength, float theX, float theY, string theColour) {
        this.sideLength = theSideLength;
        this.position = new Vector2(theX, theY);
        this.colour = theColour;
    }
}

So I’ll be eventually wanting to have an interface that works to the point that I can use the generic list List<ISpatialNode> QObjectList = new List<ISpatialNode>(); and I can add shapes to it using the code QObjectList.Add(new QCircle(50, 400, 300, "Red")); or QObjectList.Add(new QSquare(100, 400, 300, "Blue")); or something along those lines (keep in mind that I’ll be wanting to add different shapes later along the line).

Problem is, this code doesn’t seem to work when I call it from here (Initialize() is the XNA method):

protected override void Initialize() {
    QObjectList.Add(new QCircle(5, 10, 10, "Red"));

    base.Initialize();
}

So my question has two parts:

1. Why does this code give me a stackoverflow error at the set {
position = value; }
part of my QCircle and QSquare classes?

2. Would this be an efficient/effective way of utilising interfaces for
polymorphism?

  • 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-07T01:11:48+00:00Added an answer on June 7, 2026 at 1:11 am

    Stack overflow is because:

    public Vector2 position {
        get { return position; }
        set { position = value; }
    }
    

    the set actually sets the same again. You may want this:

    private Vector2 _position;
    public Vector2 position {
        get { return _position; }
        set { _position = value; }
    }
    

    or its short version:

    public Vector2 position { get; set; } //BTW, the c# standard is to use upper camel case property names
    

    Regarding the use of polymorphism, it seems right in this scenario.

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

Sidebar

Related Questions

By way of an intro, I'm creating a basic Quadtree engine for personal learning
I'm creating a Yahoo! Widget and have done this before without any problems (creating
Intro: I am working on a Car dealer application so I have a table
I am a VB programmer working my way into C#. I learned how to
I'm looking into creating a automated way to check the running version of our
I've created an intro animation to a page I'm working on using jQuery and
Almost every new website seems to have an intro video that tells prospective new
I'm learning to use Netbeans and for my intro pet projects, I don't want
I'm a physicist, and have been learning some programming, and have come across a
Short Intro Currently I have a UITableView which is filled with custom cells that

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.