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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:30:39+00:00 2026-05-22T00:30:39+00:00

hey i am thinking if i could make instance of a class with in

  • 0

hey i am thinking if i could make instance of a class with in itself…

My problem is that i ma creating 3D Spheres for planets & their moons whose data i am keeping in Object. I pass parameters to the constructor of my planet class for “Size” “Orbital Radius” “Texture” “Revolution Speed” etcetra. I Have to make another class for Moon’s of Planets which is an exact duplicate of moon class.

I was thinking if i could make the class object within itself. Pass a parameter for list\array of Objects of itself to create and like for earth i will pass “1” to create one moon and as the moon will have the same constructor i will pass “0” for no moons of moon. to create.

Something like this

class Planet
{
    Model     u_sphere;
    Texture2D u_texture;
    //Other data members

    List<Planet> Moons = new List<Planet>(); 

    Planet()
    {
    //Default Constructor
    }

    //Overloaded\Custom Constructor
    Planet(Model m, Texture2D t, int moon_count)
    {
       u_sphere  = m;
       u_texture = t;

       while(moon_count > 0)
       {
           Model     moon_sphere = LoadMesh("moon.x");
           Texture2D u_texture   = LoadTexture("moon.bmp"); 
           Planet    temp        = new Planet(moon_sphere,moon_texture,0);
           Moons.Add(temp);
           moon_count--;
       }
    }
    //Others Getters & Setters
}
  • Is it some how possible?

  • or What is the best-practice\approach to this kind of problem?

p.s I am using C# & Microsoft X.N.A Framework

  • 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-22T00:30:40+00:00Added an answer on May 22, 2026 at 12:30 am

    Yes, why not? But you may want to make an base-class of type CelestialBody from which both your Planet and Moon classes will inhert. And you don’t have to pass a Planet‘s Moons into the constructor, but you can just make Planet look like this:

    public class Moon : CelestialBody
    {
        //Moon-only properties here.
    }
    
    public class Planet : CelestialBody
    {
        //Planet-only properties here.
        public List<Moon> Moons { get; set; }
    }
    

    And then add Moons like this:

    myPlanet.Moons.Add(new Moon(...));
    

    E.g. abstract-away some of the information since a Moon is not a Planet.

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

Sidebar

Related Questions

Hey there, i am trying to make a little app that will serve multiple
Hey. I have this javascript file that I'm getting off the web and it
Hey there, I'm at the moment trying to make a product management application. The
hey all my question about how the developers makes their interface the buttons, slider,
Hey all, I would like to make possible to share links of my website
Hey guys, i'm creating a browser game where battles between monsters and users(pvp) take
Hey there. After reading here about the Service Locator pattern, it got me thinking
Hey there, is there a quick Ruby (or Rails) expression that returns nil if
Hey, I've got a bit of a problem right now trying to figure out
Hey, I'm having some trouble with this problem, and I don't even know where

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.