Is "identity" an optional feature for real-world objects?

I read somewhere

  • An object has three characteristics :
    • (e.g. name)
    • behavior (e.g. reading)
    • identification (unique student identification number)

In accordance with this information, each object will have a unique identification, so that all objects of the class will be different from each other.

but

  1. In many other places, I read that objects have two characteristics :
    • state
    • behavior

Question:

which one is correct? objects have 2 characteristics or 3 characteristics?

Suppose that there are two erasers of the same brand, type, shape, size and color.

So, should these two objects be regarded as “equal objects” since they cannot be unambiguously identified?

+7
oop
source share
7 answers

Explicit certification is optional.

However, the culmination of the state and behavior of an object is an implicit identification ; Thus,

Implicit authentication required.

Two objects can have the same internal characteristics (for example, color, size, shape), but differ in their external characteristics (for example, location, owner).

Thus, two objects can be considered equivalent in comparison with the choice of their properties, but can be considered distinguishable in terms of the culmination of all internal or external states and behavior.

+3
source share

Value objects (for example, date, color, etc.) essentially do not have the concept of identity. Two different Color MAY objects are equal if their properties (values) are equal (verified by HashCode / equals).
It is possible that your design allows you to define Color as Entity , but in very few cases.

In contrast, each object (user123, car456, etc.) has a unique identifier, and comparison is usually done using this identifier. HashCode/equals only consider id.

So, if I want to make a rule for both, this will be:

an object has two characteristics: state and behavior

+2
source share

In your provided analogy, you create two identical erasers with the same characteristics. If you show them to them and ask us, they will be different, we will say "No. They are the same."

However, if you asked us if these two erasers are actually the same unique eraser, we are wondering how we got to SE Philosophy.

Identification should not be explicitly defined. Take the String example, for example.

If I do this:

 String a = "ABCDE"; String b = "ABCDEFG".substring(0, 5); //turns into ABCDE 

We have two lines storing identical ABCDE information

We can make two comparisons:

 a == b //false a.equals(b) //true 

These two lines are similar to your two erasers. They are equal in that they both consist of ABCDE, but they are not actually the same singular string, but two separate sets of characters that coincide by coincidence.

Both a and b point to a unique link to "ABCDE". In this case, we do not have an explicit identity, but both a and b are unique links, so the language knows: "Hey, these are two different lines."

Now back to the erase example. In this case, we were not given any way to differentiate the two, but we can still distinguish them.

One eraser on the left, one on the right (or, nevertheless, they are located)

These erasers indirectly gave us a personality, so we understand that these are two different erasers with the same properties.

We can explicitly identify the identifier by specifying the serial numbers or names of the lasers. They may look the same, but now they have clear identities, and not the ones we made up in our heads.

+2
source share

I would say that you can consider Identity as part of the state ... The vast majority of classes will have some form of identification stored with them, but this is not a complicated and quick rule. Consider, for example, strings ...

However, in the real world, the vast majority of what you do will involve talking to databases and putting information together. Keys are crucial for this, and your identity is basically your key ... In the old days, just because it was in your database, it doesn’t mean that you would do it in your class, but in this era object relational mappers I would get used to the idea if I were you ...

+1
source share

If two objects are completely identical in all respects, there is no way to distinguish them, therefore they are one and the same object. Individual objects - those that are not the same object, differ from each other because they differ in something. Your two erasers may have the same brand, appearance, shape, size and color, but they differ in their position: they do not physically overlap in space. You can place them on a table next to each other and see them in different places, so you know that they are different objects.

You may find it useful to consider two different equivalent objects, even if they differ in some of their properties - two erasers in different physical places, but the same in other characteristics, or two data structures at different memory addresses, but containing the same data , This is the difference between the Java equals() method and its == operator.

+1
source share

You describe the difference between referential equality (literally the same object) and Value Equality (have the same properties). Regardless of whether a given object should have reference equality or equal value, it does NOT depend solely on the object itself; It depends on the context. In most cases, the dollar bill has value equality: one is as good as the other, we freely replace them, and we are not at all interested in the “identity” of each individual account. Nevertheless, for a counterfeit specialist working in the treasury department, all dollar bills do not match, and the individuality of a separate bill is of great importance.

Another example would be a plane. If I am on an American Airlines flight, regardless of whether the aircraft has a 737 or S80, I have 6 seats in a row, and the other 5, each has AC power in each seat and the other - But I am only interested in the plane properties , not identities; one 737 is as good as another for me. But for the mechanics who support the planes, identity matters. One plane has just been serviced, and the other is approaching its service life; tracking which is extremely important.

So, before you decide how to model your object, consider the context in which it will be used.

+1
source share

I approve of most of @Wyzard's answer , but it is not too far. To be clear:

YES! Identification is optional for real-world objects.

Even objects that are truly not identical in every way - for example, two potato chips - are the same for all practical purposes. They are identical in use. No one cares about their personality. There is no naming scheme, no serial numbers, no hash values ​​to distinguish between them in any way. Your two erasers or two oysters that you just bought in local raw seafood may have some different characteristics and they have physical identity (i.e. they cannot simultaneously occupy the same place), but there is no meaningful way talk about them, but point to them (“it's more than that!”) or describe them (“blue eraser - no, another that looks like it was used a little”). Their identification is only temporary, and only that which is assigned by individual users. Very few people try to name their erasers or their oysters. ("Go to work, Fred! Drain!" Or "Francine was delicious! Bring me another one! I'll call her Sally Wellfleet!")

This unrealistic identity applies to many manufactured products, such as nails, pieces of lumber, ball bearings, ibuprofen caps, or ibuprofen bottles. Producers often track cohort identity — the batch number of which they are part, for example. But this is the finest granularity for which genuine identification information is created or considered.

Now this does not apply to electronic devices. Even the smallest Ethernet adapter, Bluetooth transponder or RFID tag has a sophisticated identification system. It has a manufacturer, model / part number, serial number and often issued identification (device identifier). It can also be a "current address", such as a MAC address or another "I work in / as." Many of these pieces of identifying information are available through reflection . The individual chips that make up the device may have a batch identifier manufacturing system, but the operating device has a more open, individual identification.

But most real-world objects are not electronic transponders, and they do not have a significant identity, other than what we assign.

+1
source share

All Articles