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

  • Home
  • SEARCH
  • 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 6239381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:22:59+00:00 2026-05-24T11:22:59+00:00

I am writing a program which will manipulate certain objects, let’s call them Words.

  • 0

I am writing a program which will manipulate certain objects, let’s call them “Words”. Each word is an instance of one of several classes. There can be lots and lots of these at a time.

Each of these Word objects needs access to a dictionary, stored in an XML file. I don’t feel like each Word object should be loading the XML file separately. The Word objects should be able to access some global pool of program data.

What’s the best way to deal with this? Should I have a class called ProgramData which contains the XML document and gets passed to every Word object when they are created? This won’t cause multiple instances of the XML file to be loaded into memory, will it? Can I do what I want to do without passing ProgramData to every new object?

  • 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-24T11:23:00+00:00Added an answer on May 24, 2026 at 11:23 am

    You should load the XML file into one instance of ProgramData, and then pass that instance into each Word instance (maybe in the constructor). You could also make a static property in the Word class that you set before you start instantiating Words, but be sure to use locking for thread safety.

    Your alternative is the Singleton pattern, but trust me, you don’t want to go down that road.

    Edit: Just to be clearer, this is the first option (the one I’d use):

    public class Word
    {
       private ProgramData _Data
       public Word(ProgramData data)
       {
          _Data = data;
       }
    
       public void MethodThatUsesData
       {
          // _Data.TryGetValue()
       }
    }
    
    // in your main method or initialization routine:
    ProgramData data = MethodThatLoadsData();
    Word w = new Word(data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program which will use scan conversion on triangles to fill in
I'm writing a program which will allow to load a specific managed .DLL file
I am writing a program in Ruby which will search for strings in text
I'm about to start writing a program which will attempt to extract data from
I am writing a c++ program which sooner or later will need to be
I am writing a program in windows in C++ in which users will be
I need to writing a Delphi program which will monitor a folder for changes
I'm writing a program which will need to do a very large number of
I'm writing a C++ program for a Windows 7 user which will be the
I am writing a java program which will create a database LocalStations where it

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.