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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:16:01+00:00 2026-06-09T15:16:01+00:00

My application has InstrumentFactory – the only place where I create Instrument instance. Each

  • 0

My application has InstrumentFactory – the only place where I create Instrument instance. Each instrument instance contains several fields, such as Ticker=MSFT and GateId=1 and also unique Id =1.

And now I realized that I almost never need Instrument instance. In 90% of cases I just need Id. For example now I have such method:

public InstrumentInfo GetInstrumentInfo(Instrument instrument)
{
    return instrumentInfos[instrument.Id];
}

We know that we should not pass in parameters more information than required. So this code probably should be refactored to:

public InstrumentInfo GetInstrumentInfo(int instrumentId)
{
    return instrumentInfos[instrumentId];
}

90% of my code can now be refactored to use instrumentId instead of Instrument.

Should I do that? Changing everywhere Instrument to instrumentId will make it as a hard requirement (each Instrument should have exactly one unique id). But what benefits will I have? In return of “hard requirements” I want to have some benefits for that… (speed, readability?) But I don’t see them.

  • 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-09T15:16:03+00:00Added an answer on June 9, 2026 at 3:16 pm

    Using ids everywhere instead of the object is wrong approach and it goes against the spirit of OOP.

    There are two big advantages to using the object itself:

    1. It’s type-safe. You can’t accidentally pass something like Person to the first version, but you can accidentally pass person.Id to the second.
    2. It makes your code easy to modify. If, in the future, you decide that you need long ids, or some other way to identify a unique Instrument, you won’t need to change the calling code.

    And you should probably change your dictionary too, it should be something like Dictionary<Instrument, InstrumentInfo>, not Dictionary<int, InstrumentInfo>, like you have now. This way, you get both of the advantages there too. To make it work, you need to implement equality in Instrument, which means properly overriding Equals() and GetHashCode() and ideally also implementing IEquatable<Instrument>.

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

Sidebar

Related Questions

My application has multiple SQLite tables(around 20 with different fields). This I have created
My application has a simple data model with 70 read-only records grouped into six
My application has pages of two basic types: forms and tables. As such, I
My application has many aggregate fields that need to be updated when any related
My application has couple of backbone models and collection. I want to place an
My application has only one service class (not activity) in which I keep value
My application has a requirement that we need to encrypt index fields. Right now
My application has an sqlite DB, where some of the fields are null or
My application has several jqGrids that may or may not contain enough rows to
My application has a ListView control that has data added to it across several

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.