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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:46:41+00:00 2026-05-15T00:46:41+00:00

I don’t quite know how to ask this question, so I’ll phrase it as

  • 0

I don’t quite know how to ask this question, so I’ll phrase it as an example instead:

Imagine in an application you have a Country object. There are two properties of this object: Name, and a ‘Bordering Countries‘ collection. More properties might be added later, but it will be the kind of information that would change very rarely (e.g. changes of country names/borders)

Lets say this application needs to know about all of the countries in the world. Where would you store these object’s state? How would you new them up? It seems silly to store all this state in the DB, since it won’t change very often.

One option might be to have an abstract ‘country’ base object, and have a class for each country inheriting from this with the details of each country. But this doesn’t seem quite right to me.

What is the proper way of dealing with these kinds of objects?

UPDATES:

Someone asked about language: C#

Also, I’m coming at this from a web application perspective, so there wouldn’t be multiple client installations where I’d have to worry about updating hard coded values.

Most people have suggested not hardcoding the data, but using the DB or XML files to store the data. Could anyone provide an example of how this kind of object would be ‘newed up’ (from e.g. an XML file)? Would you use some kind of helper or factory method to obtain instance of a particular country?

  • 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-15T00:46:42+00:00Added an answer on May 15, 2026 at 12:46 am

    You’ve got a variety of answers, so I thought I’d add my $0.02 worth.

    Personally I alway hard code fixed lists like this (same with postcodes). That being said, when I’m at your position, I’ll always optimize for readability. ie What will make sense in 6 months time, when you’ve forgotten about this project and have to do some maintenance?

    If I had to do it with a database:

    public class Country
        {
            public string Name { get; set; }
            public Country[] BorderingCountries { get; set; }
    
            public Country(iDB db, string name)
            {
                BorderingCountries = db.BorderingCountriesGet(name);
            }
        }
    

    Your unit test:

    public UnitTest1()
        {
            iDB db = new DB();
            Country c = new Country(db, "Spain");
            Assert.AreEqual(2, c.BorderingCountries.Count());
            Assert.AreEqual(1, c.BorderingCountries.Count(b => b.Name == "France"));
            Assert.AreEqual(1, c.BorderingCountries.Count(b => b.Name == "Portugal"));
        }
    

    Oops! You probably want to populate the whole list (not one at a time!)
    DB:

    static void Main(string[] args)
        {
            Countries countries = new Countries(new DB());
        }
    
    public class Countries
        {
            public List<Country> Items { get; set; }
            public Countries(iDB db)
            {
                tblCountry[] countries = db.BorderingCountries();
                Items = new List<Country>();
                Country country = null;
                foreach (var c in countries)
                {
                    if (country == null || country.Name != c.Name)
                    {
                        country = new Country(c.Name);
                        Items.Add(country);
                    }
                    country.BorderingCountries.Add(new Country(c.BorderingCountry));
                }
            }
        }
    
    
        public class Country
        {
            public string Name { get; set; }
            public List<Country> BorderingCountries { get; set; }
            public Country(string name)
            {
                this.Name = name;
                BorderingCountries = new List<Country>();
            }
        }
    
        public interface iDB
        {
            tblCountry[] BorderingCountries();
        }
    
        public class DB : iDB
        {
            public tblCountry[] BorderingCountries()
            {
                using (DataClassesDataContext dc = new DataClassesDataContext())
                {
                    return dc.tblCountries.ToArray();
                }
            }
    
        }
    

    If I was hardcoding it:

    public class Countries
    {
        public List<Country> Items { get; set; }
        public Countries()
        {
            Items = new List<Country>();
            Items.Add(new Country { Name = "Spain", BorderingCountries = new string[] { "France", "Portugal" }});
            Items.Add(new Country { Name = "France", BorderingCountries = new string[] {"Spain","Belgium"});
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this has been asked before, so point me to another question
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
Don't know if this has been answered before. Have custom routes to users. If
don't know better title for this, but here's my code. I have class user
Don't know why but I can't find a solution to this. I have 3
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't know whether this is really possible, but I'm trying my best. If
I don't know if this is a well known 'thing' or something new in
Don't know if I worded the question right, but basically what I want to

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.