Object orientation: what defines the identity of an entity?

Asked

Viewed 242 times

4

I know that the concept of identity, in this context, is abstract and it is precisely to make it more tangible that I asked this question. Follow the questions:

  • Only database id defines an entity’s identity?
  • Which criterion defines the identity that characterizes an entity?
  • In addition to the database id, names and other types of identification (numbers, codes, etc.) fit into this idea of identity that defines an entity?

Notes to guide answers

The entity here is related to objects that represent things within a project and not database entity. I.e., entity in that issue is the counterparty of the value Objects.

Nor do I refer to how programming languages implement identity internally in memory. I speak of objects that are entities of the business rule (and what defines the identity in them). I think this concept of entity comes from the DDD (I have no knowledge of this methodology).

  • Identity is not any characteristic that uniquely determines an instance of this entity?

  • identity is an attribute that defines a unique value to identify an element of that entity. ID is a, CPF for example is the tax identity of a citizen, the name may be the same, but the CPF will not, and so on. The criterion is simple: a single attribute, which does not repeat, which makes it possible to identify a single element of the entity. An entity for example of State, could be the acronym (AC, AL, AP, AM, etc)

2 answers

4


What defines the identity of an entity?

I don’t like the definition of the term given in the context of object orientation, so I’ll just put what’s on Wikipedia not to give a definition of my own:

An identity in object-oriented design and object-oriented analysis describes the property of objects that differentiates them from other objects. This is closely related to the philosophical concept of identity.

In terms of real identity of objects in the most universal sense this does not fit well, but the question has a more specific context.

Only database id defines an entity’s identity?

Not necessarily, but it is very common that it is him in the database. I suggest to take a look at Surrogate Key and Natural Key. The id may be the identifier of that line in the database.

It is not necessarily the identity of that logical entity from the point of view of business modeling. It can be another code, a document number, or even a (rarer) name. It can even be the id also, if the business model still makes sense with that.

From the point of view of the data bank mechanism the primary key used will be the identity, where the id or not. But reinforcement that only applies to the SGDB, on the business model depends.

Which criterion defines the identity that characterizes an entity?

Depending on each entity, the biggest reason is that it is unique in every data collection. Identity can even be composed of multiple data. In the database it’s usually the id because he’s unique.

From the strict point of view of object orientation there are no rules so specific beyond oneness.

The question is a little confusing for putting the tag of OOP and talk of database, where the term has different meanings, including in some contexts, such as DDD only to quote one, may have specificities on these rules.

3

the entity here is related to objects representing things within a project and not database entity.

As you said, the concept is abstract. The identity of an object is what defines that it is that specific object, not another. Object-oriented languages implement this, but do not necessarily expose this implementation to the programmer. Or, even if exposed, in general it is not necessary to use it.

Generally speaking, the identity of an object at runtime is what will be used to represent the object in the context of an equality comparison with another object, for example. Usually this will be a value (a unique number) saved somewhere in the memory allocated by the program.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.