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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:08:00+00:00 2026-05-23T07:08:00+00:00

Let’s say I have a Car class in a game that can be played

  • 0

Let’s say I have a Car class in a game that can be played over a network. We have basic properties that never change like model and engineSize which are the same for every game. We have runtime properties such as current location and current speed that we might want to save the current game and reload later. Finally, we have data that we must transmit to other players over the network – probably in this case location and speed again, but let’s say speed and distanceAwayFromYou.

So we have a class that might look something like (ignore exact syntax or debates over identities):

public Car
{
    public string Model; /* Base data */
    public int EngineSize; /* Base data */
    public PointF Location; /* Runtime data */
    public double Speed; /* Runtime and network data */
    public double distanceAwayFromYou; /* Network data */
}

Now, I could write an schema to create serializable partial classes (using xsd.exe, for example) for base data, for runtime data, or for network data. But here I have a single class with three subsets of XML data to use:

Base data:

<Car>
    <Model>Honda</Model>
    <EngineSize>2999</EngineSize>
</Car>

Runtime data:

<Car>
    <Location><X>10</X><Y>20</Y></Location>
    <Speed>60.4</Speed>
</Car>

Network data:

<Car>
    <Speed>60.4</Speed>
    <DistanceFromYou>45.67</DistanceFromYou>
</Car>

I have previously solved this using custom attributes and reflection; however, it’s not pretty and – as far as I know – can’t validate automatically against a schema. Is there a simpler way, or how would you do it?

Thanks.

  • 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-23T07:08:01+00:00Added an answer on May 23, 2026 at 7:08 am

    In that case, try this:

    1. Make IRuntime interface:

      public interface IRuntime
      {       
          PointF Location
          {
              get;
              set;
          }
      
          double Speed
          {
              get;
              set;
          }
      }
      
    2. Make INetwork interface:

      public interface INetwork
      {
          double Speed
          {
              get;
              set;
          }
      
          double DistanceAwayFromYou
          {
              get;
              set;
          }
      }
      
    3. Make a class that inherits from these interface:

      class Car : IRuntime, INetwork
      {
          private string _model = string.Empty;
          private int _engineSize = 0;
          private PointF _location = new PointF();
          private double _distanceAwayFromYou = 0; 
          private double _runtimeSpeed = 0;
          private double _networkSpeed = 0;
      
          public string Model
          {
              get
              {
                  return _model;
              }
              set
              {
                  if (_model != value)
                  {
                      _model = value;
                  }
              }
          }
      
          public int EngineSize
          {
              get
              {
                  return _engineSize;
              }
              set
              {
                  if (_engineSize != value)
                  {
                      _engineSize = value;
                  }
              }
          }
      
          PointF IRuntime.Location
          {
              get
              {
                  return _location;
              }
              set
              {
                  if (_location != value)
                  {
                      _location = value;
                  }
              }
          }
      
      
          double INetwork.DistanceAwayFromYou
          {
              get
              {
                  return _distanceAwayFromYou;
              }
              set
              {
                  if (_distanceAwayFromYou != value)
                  {
                      _distanceAwayFromYou = value;
                  }
              }
          }
      
      
          double IRuntime.Speed
          {
              get
              {
                  return _runtimeSpeed;
              }
              set
              {
                  if (_runtimeSpeed != value)
                  {
                      _runtimeSpeed = value;
                  }
              }
          }
      
          double INetwork.Speed
          {
              get
              {
                  return _networkSpeed;
              }
              set
              {
                  if (_networkSpeed != value)
                  {
                      _networkSpeed = value;
                  }
              }
          }
      }
      

    Then in your consuming code you can do as follows:

        Car myCar = new Car();
        //Note that you are able to set only two properties using an instance of Car i.e. Model and EngineSize
        myCar.Model = "test";
        myCar.EngineSize = 9; 
    

    You can save the above if you like. But if you want to save runtime data, then do as follows:

        IRuntime runtimeCar = (IRuntime)myCar;
        //Note that now you are able to set properties related to runtime data. This is upcasting.
        runtimeCar.Location = new PointF(20, 30);
        runtimeCar.Speed = 50;        
    

    For data related to network, you can do as follows:

        INetwork networkCar = (INetwork)myCar;
        //Now you are only able to set properties related to network data using upcast.
        networkCar.Speed = 70;
        networkCar.DistanceAwayFromYou = 50;
    

    Hope this helps.

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

Sidebar

Related Questions

Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say that I have a model that handles recipes, and I want to
Let's suppose I have a Discussion model, and that a discussion can be tagged.
Let's say that I have a set of relations that looks like this: relations
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a

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.