Alex Rivera | Logout

What is the difference between identity and equality in OOP?

Asked 2009-11-07T12:25:07.750
36

What is the difference between identity and equality in OOP (Object Oriented Programming)?

Edit
Report

2 Answers

2

Identity concept is quite philosophical, that's why you shouldn't reconduce it just to references.

You can say that two identities are the same if a change to the first is reflected on the second and vice-versa. Of course this includes also sharing the same memory address but in general while identity is related to the attributes of the object, equality is used to check whenever two objects are identical, but this doesn't include identity.

The viceversa is quite obvious, if two items have the same identity they are also equal (in equality terms of being interchangeable).

answered 2009-11-07T12:35:59.430
2

Think about the words "identical" and "equivalent". If two things are identical, they have the same identity; they are same thing. If they are equivalent, one can be substituted for the other without affecting the outcome; they have the same behavior and properties.

answered 2009-11-07T12:36:14.950

Your Answer