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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:59:14+00:00 2026-05-10T15:59:14+00:00

This is a question with many answers – I am interested in knowing what

  • 0

This is a question with many answers – I am interested in knowing what others consider to be ‘best practice’.

Consider the following situation: you have an object-oriented program that contains one or more data structures that are needed by many different classes. How do you make these data structures accessible?

  1. You can explicitly pass references around, for example, in the constructors. This is the ‘proper’ solution, but it means duplicating parameters and instance variables all over the program. This makes changes or additions to the global data difficult.

  2. You can put all of the data structures inside of a single object, and pass around references to this object. This can either be an object created just for this purpose, or it could be the ‘main’ object of your program. This simplifies the problems of (1), but the data structures may or may not have anything to do with one another, and collecting them together in a single object is pretty arbitrary.

  3. You can make the data structures ‘static’. This lets you reference them directly from other classes, without having to pass around references. This entirely avoids the disadvantages of (1), but is clearly not OO. This also means that there can only ever be a single instance of the program.

When there are a lot of data structures, all required by a lot of classes, I tend to use (2). This is a compromise between OO-purity and practicality. What do other folks do? (For what it’s worth, I mostly come from the Java world, but this discussion is applicable to any OO 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. 2026-05-10T15:59:15+00:00Added an answer on May 10, 2026 at 3:59 pm

    Global data isn’t as bad as many OO purists claim!

    After all, when implementing OO classes you’ve usually using an API to your OS. What the heck is this if it isn’t a huge pile of global data and services!

    If you use some global stuff in your program, you’re merely extending this huge environment your class implementation can already see of the OS with a bit of data that is domain specific to your app.

    Passing pointers/references everywhere is often taught in OO courses and books, academically it sounds nice. Pragmatically, it is often the thing to do, but it is misguided to follow this rule blindly and absolutely. For a decent sized program, you can end up with a pile of references being passed all over the place and it can result in completely unnecessary drudgery work.

    Globally accessible services/data providers (abstracted away behind a nice interface obviously) are pretty much a must in a decent sized app.

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

Sidebar

Related Questions

Variants of this question have been asked many times, but none of the answers
I just came across this question about initializing local variables. Many of the answers
Haven't seen many Geneva related questions yet, I have posted this question in the
I found many answers to this question on Google, but none of them seem
Although I found many answers and discussions about this question, I am unable to
I know this question has been asked before, but many answers don't give clear
This is a complicated question with many possible answers, so I'll break down my
I apologize if this question is a duplicate. I have read many other mysqli
I had tried looking up on here many different answers to this question and
Caution: This question is over nine years old! Your best option is to search

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.