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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:58:31+00:00 2026-06-01T12:58:31+00:00

Suppose a class whose responsibility is to set parameters to a JDBC query. It

  • 0

Suppose a class whose responsibility is to set parameters to a JDBC query.

It would have a fillParameters() method and a PreparedStatement as a field because shared across all private submethods.

Furthermore, these submethods need to know about current JDBC parameter index.

So two solutions may adopted :

  • Pass current index into each method as a local parameter (redondant if there are many submethods)

  • Declare current index position as a field (or attribute) so that no need to pass it through multiple method parameters. But the drawback is that it can cause side-effect if we imagine that a second call to this method is made with the same object instance (for a particular reason, no real usecase but imagine…). Indeed, it would be compulsory to reinitialize current Index Posion to 0 before calling all process made by submethods.

What is the best-practice ?

public void fillParameters(){
this.currentIndex = 0; //reinitialize to first index !
//....call to each submethods without need to pass currentIndex as local parameter
}

Or :

public void fillParameters(){
int currentIndex = 0;
//....call to each submethods with currentPosition as index like :
feedFirstParameter(++currentIndex);
feedSecondParameter(++currentIndex);
}
  • 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-01T12:58:32+00:00Added an answer on June 1, 2026 at 12:58 pm

    The local variable option is better encapsulation of the details of how your method works. That will be easier to maintain and less likely to have side effects as you point out. If overhead becomes an issue you can optimize. I’m not sure there’s a best practice, since a design depends on what’s important to you. The best thing either way would be to document your reasoning in the code.

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

Sidebar

Related Questions

Suppose I have a file X.h which defines a class X, whose methods are
Suppose I have: class Foo { public String Bar { get; set; } }
Suppose I have a partial view called UserDetails whose @model clause is set to
Suppose I have a simple interface representing a complex number, whose instances would be
Suppose I have this class: template</*some other parameters here */class toggle> class Foo {
Good night, Let's suppose I have a class which implements a NFA/DFA whose transitions
Suppose class B extends class A . I have a List<A> that I happen
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
Suppose I have: class Foo { ... }; class Bar : public Foo {
Suppose I have class A { public: void print(){cout<<A; }}; class B: public 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.