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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:21:45+00:00 2026-06-05T12:21:45+00:00

So let’s say I have a Clone object with these properties. Clone might have

  • 0

So let’s say I have a Clone object with these properties. Clone might have different mass or name based on the file it was loaded from, but these values never change at runtime. However, Clone instances to have some autonomy and properties which do change per instance, so they can’t all be the same instance.

public class Clone
{
    public float Mass { get; protected set; }
    public string Name { get; protected set; }
    public Clone(string filePath)
    {
        Name = //read name from file
        Mass = //read mass from file
    }
}

Now, what I want to know is, what are the benefits and drawbacks (if any) of doing this instead:

public class CloneInfo
{
    public float Mass;
}
public static class Database
{
    public static Dictionary<string, CloneInfo> Lookup;
    [...load whole dictionary from files...]
}
public class Clone
{
    public string Name { get; protected set; }
    public float Mass { get { return Database.Lookup[Name].Mass; } }
    public Clone(string name)
    {
        Name = name;
    }
}

With this ‘redirecting’ method, I keep the simple syntax of Clone.Mass, but don’t have to store a Mass value for each instance. Since I’ve got thousands of clones wandering about, this is a good thing. I’m mainly interested in ‘redirecting’ because of the syntax. I realize that I could simply manually do the database lookup every time I wanted a particular clone’s mass, but I’d rather keep the usage of the class nice and straightforward. Is there any drawback to this? Is the property going to be slower than direct lookup in the static database? Does the property take up any space in a Clone instance?

Or, perhaps, is this a use case C# already has an answer for which I’m not aware of? Seems like write-once properties which are common among many instances might be somewhere in this beautiful language.

  • 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-05T12:21:47+00:00Added an answer on June 5, 2026 at 12:21 pm

    If all the clones of a certain type have the same mass, that sounds like a job for subclassing:

    class Clone
    {
        public abstract float Mass { get; }
    }
    class HeavyClone : Clone
    {
        public override float Mass { get { return 12345.6; } }
    }
    class LightClone : Clone
    {
        public override float Mass { get { return 1.23456; } }
    }
    

    More to the point of your question: if you are more constrained by memory than by processing time, your approach may give some benefit. If memory is plentiful, and cache performance is not an issue, the approach you suggest probably has little value. It certainly seems to complicate the code quite a bit.

    The usual advice is: write simple code, measure the performance, and, if the performance is inadequate, address the performance bottlenecks. That way, you only have complicated code in places where it actually helps your application’s performance.

    Another thought: instead of having have the clone index into the dictionary with the Name string, why not just have a CloneInfo field:

    public class CloneInfo  
    {  
        public float Mass;  
    }  
    public class Clone  
    {  
        private CloneInfo _info;  
        public float Mass { get { return _info.Mass; } }  
        public Clone(CloneInfo info)  
        {  
            _info = info;
        }  
    }  
    
    • 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 a select list as follows: <select name='languages'> <option value='german'>German</option> <option
Let's say I have window.open (without name parameter), scattered in my project and I
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say we have this code: <form action='' method='POST' enctype='multipart/form-data'> <input type='file' name='userFile'><br> <input
Let's suppose I have all of these already provided: The name of a table
Let's say I have the following classes : public class MyProductCode { private String
Let's say I have a due date and a reminder timespan . How do
Let's say you have a method that expects a numerical value as an argument.
Let's say I have a bunch of links that share a click event: <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.