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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:02:29+00:00 2026-06-17T18:02:29+00:00

So I have a value object , (arbitrarily say money), and I want to

  • 0

So I have a value object, (arbitrarily say money), and I want to implement equality for it. I am aware of the intended/default behavior for == and .Equals() (reference and data equality).

In this case though, I want to be able to compare two objects, and say that they are equivalent for calculations (e.g. 1m and 3 ft are equivalent)
however for persistence (using NHibernate, where isDirty I think depends on equality), user display and selection of currency, I want them to be considered different.

Should I, in this case,

  1. Have different behavior for == and .Equals() (and which should do what),
  2. Wherever I want to check equivalency, just check each property (means extra code)
  3. Implement a method like .IsEquivalent() (I’d prefer not to do the latter)
  4. Something else that I’m missing

Is there a best practice/pattern I should follow?
Thanks

Edit:
i got some responses regarding changing exchange rates. so updating for clarity. lets say height, and not currency

  • I’d like to clarify, some assumptions:
  • // ignore: Value object contains decimal amount, string / class currency
  • // ignore: Exchange rates do not change.
  • // ignore: the class currency is aware of its exhange rate to and from the other
  • value object contains decimal qty, string / class unit
  • the class unit is aware of its conversion to and from the other
  • i do not intend to expand rates / conversions etc

I’m more concerned about practices and patterns, as opposed to implementing currency.
Basically, the same approach to a person’s height, where height is a value object, ({1,m} to {3,ft}, where 1m is always “equal”/”equivalent” to 3ft)

  • 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-17T18:02:30+00:00Added an answer on June 17, 2026 at 6:02 pm

    I would not treat 1.0 USD as equal to 0.63 GBP. In order to check for equality of monitary value, you’d need more information than just the two values – you’d also need the current exchange rate, etc. This is especially true, as the same two values won’t be equal consistently, and equality should always be true if the two values are ever equal.

    As such, a method, such as AreEquivalentMonitaryValues(), seems appropriate – especially given that extra info is required.

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

Sidebar

Related Questions

I have a page in which I want to maintain the value of object
Say I have an object containing a value. I wish to get the index
I have an object Document with nested Properties (Name, Value) collection. Now I want
I am getting the following exception: Nullable object must have a value Everything was
I have an object whose value may be one of several array types like
I have been trying to assign value to an object array that is defined
I have a List with array of object values. I have to display value
I have an object that returns a value if successful and false (or nil)
I have a Generic List object which hold below table as its own value.
I have a class with a Property called 'Value' which is of type Object.

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.