Compare 2 objects via Billy McCafferty

  • If two objects have IDs, and have the same IDs, then they may be considered equal without examining them further.  (I’m assuming ID to be an identity field, or equivalent, in the DB.)
  • If two objects have IDs, but have different IDs, than they may be considered not equal without examining them further.  E.g., If customer A has an ID of 4 while customer B has an ID of 5, then they are not equal, QED.
  • If neither object has an ID or only one of them has an ID, but their “business value signatures” are identical, then they’re equal.  E.g., customer A has an ID of 4 and a social-security-number of 123-45-6789 while customer B has no ID but also has a social-security-number of 123-45-6789.  In this case, customer A and customer B are equal.  By “business signatures,” I imply a combination of those properties which deem an entity unique, regardless of its ID.  (As a side, see Eric Evans’ Domain Driven Design for a stellar conversation of value and entity objects.  A summary version is also available.)
  • If one of them is null, then they are not equal.  (Whoo, that was easy.)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s