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

The Archive Base Latest Questions

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

While writing yet another class full of methods that access database tables to work,

  • 0

While writing yet another class full of methods that access database tables to work, I started wondering how I may best write these methods in the case that the application may need to be run in a way that was the least load intensive on the server

For example, if I have the method foo which queries for and displays bars, I could write it like:

function foo (params) {
   this->query_db("select bar from bars where bar != foo");

   for all bars display bar
}

I was wondering if it may be better design to write something like

function foo(bars,params) {
   if(!bars) { bars = this->query_db("select bar from bars where bar != foo"); }

   for all bars display bar
}

In the second method bars is passed to the method foo as an array, this would allow for two things, a) if bars has already been queried in the same instance, a call to the database is avoided b) foo can now be used simply by passing an array in other instances you may want to use foo without using data from the database

Is this a good method of design for programs that use databases? Is there perhaps a software pattern out there that suggests similar design to this? Or…is this just silly? 😉

  • 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-22T03:16:25+00:00Added an answer on May 22, 2026 at 3:16 am

    Point a) is potentially valid, as long as you’re aware of what you’re doing: implementing a cache in front of the database. That means you have to be thinking about all the usual considerations cache implementors worry about: tradeoff of cache size vs. memory consumption, how long to retain cached data, the possibility that the cache may no longer be valid if the underlying database has changed, etc. You might also want to consider using an object-relational mapping tool (such as Hibernate), which may take care of some of this kind of caching for you.

    I think your point (b) is actually an anti-pattern.

    A method that might be summarized as “query the the database and display the results, or display some data you pass it without doing a query” is begging to be refactored so it’s only doing one thing.

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

Sidebar

Related Questions

while writing a custom attribute in C# i was wondering if there are any
I'm engaged in writing a product using LinqToSql for data-access. While we're rapidly developing,
I find myself writing code that looks like this a lot: set<int> affected_items; while
I'm writing an application (basically its yet another iBooks clone) which consumes a lot
What are the consideration while writing the Helper extension methods in .cshtml vs .cs
While writing a file using ofstream, how do I know when the file's size
I got this doubt while writing some code. Is 'bool' a basic datatype defined
OK, so instead of writing a whole bunch of access control specs, and duplicating
On a regular basis I find myself writing little utility programs that use some
Would anyone know how to properly hide classes, methods and properties from intellisense while

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.