Concept of class, entity and objects

Asked

Viewed 4,107 times

11

I’m reading about classes in C#, and an excerpt left me a little confused.

I know that classes are objects in C#, and can be used in various ways.

My doubt is in the following sentence:

"A class can have both the attributes and methods of a system entity"

Would the class itself be considered an entity of the system or not? If so, I believe that the above sentence would have to be different.

When we speak of entities, we can refer only to the class or to any object?

  • You saw it in some book, on the web there’s nothing like it.

2 answers

17


I know that classes are objects in C#, and can be used in various ways.

Class is not an object. Class is a model to be followed, object uses this model to structure.

Think about development time and runtime. Class is defined in the first, the object in the second. Class only exists in your code, object only exists when the application is running. It is a simplification, but so it is easy to understand.

Comparing to database, the structure defined for a table is the class, each row of this table is the object.

Would the class itself be considered an entity of the system or not? If so, I believe that the above sentence would have to be different.

Yes, a class is an entity model of the system. I don’t see why it should be different. From an architectural point of view, the class is a model representing an entity. Architecture only exists on paper, its realization will generate objects. Objects function as entities. Example: the class tells how a client’s data should be organized, but a client will only exist in fact on objects.

Just as tables in Dbs are entities, classes are entities in the modeling. Separate the real data model from your mind.

Just be careful because in programming languages mainstream where it reads attribute, understand as fields, or even properties, since the term is used for something else.

When we speak of entities, we can refer only to the class or to any object?

The entity itself is the object. The class is a type of an entity, or in other words, it is an object class. Class comes from classification, comes from generalization of a group of objects with the same characteristics. Class is an abstraction of the entity. When we’re talking about abstraction, we use the term entity, but actually that’s a kind of entity.

Think of a map. We point to such a city. We are pointing to an abstraction that represents the city on that screen, but it is not the city. The city is an entity. On the map we treat that representation as if it were an entity. The term can be used in both contexts, but the most correct would be to say "representation of the city on the map". The important thing is that if you only speak "city" on a map everyone understands that it is only one representation.

A philosophical note

Technically the object of the application is also not the entity, we just use the term so to facilitate. The same entity exists only in the real world. So a customer is the same customer, is a person or a company. The object in your application works as a representative figure. For your application the real world does not exist. Tron exists only in fiction.

Cena de Tron

  • in your post you said the following: "Class typifies what will be modeled by it. It determines the possible states and behaviors that objects can have. "I understand that from a class objects are created. Whether objects are generated from classes. Classes are considered what ? It is not clear yet. Can you explain better

  • @Diegofarias was out of time yesterday, I gave an improved answer. I think the answer that I Linkei gives a very clear example.

  • Ok, I will read and any question notice or post a new question. Thank you

  • It became clearer, however, this question of abstraction confuses my head. As I am reading a lot about these subjects, I believe that this confusion will disappear.

  • If I have a dictionary class and register a word with its meaning, that word with its meaning is an object, and this is unique. Was this class abstracted, in this case, from an idea? The idea of bringing together several words with their meanings (dictionary)? If dictionary is an entity, the entity does not exist only in the real world. And abstract would be what exactly? Would it be an analysis of something real or an idea? I’m still finding it confusing: class, object and entity. I thought entity was a class.

  • When an entity and relationship diagram is formulated, you create an entity, for example Person entity, wouldn’t this be a class? Because you said entity is the object and not the class.

  • You see a person, this is a real-world entity, so you make an abstraction (analysis) of that person and create a classification for that person, which would be a class, is that it? And in the case of the dictionary before it even exists, we make its formulation in our mind, it is an idea, we represent this idea in a Dictionary class, but if it were to elaborate an entity diagram, Dictionary would not be an entity?

  • The dictionary is an object, the word is a smaller object that will be inside this larger object, dictionary is a container. It’s an abstraction. To abstract, in this context, is to make a representation in your code, is to create something that says what the real entity looks like. You’re on the right track. Within its code the entity is a class, but only in its code, because the physical entity in the real world cannot be within its code. A class is a representation of the entity, your mistake may be there, it is not class. In general we even talk like simplification, but it is not the right concept.

  • A specific person is an object, the idea of a person is a class. The entity is the person, in the computer will be an object, the representation of an entity that is classified as a person, in the computer will be a class. You don’t analyze a person, you analyze people in general. A person can be used as a basis to see more easily how a person is composed, how they behave. In the diagram we can say that it is an entity because a diagram is already a representation (a drawing for you to visualize "this idea") ...

  • ... when you say you are an entity it is as if you were seeing the real ecosystem ready, there "on paper" is just a model, and in the code you say how is the model by a class (in languages that have classes, of course), it is for you to think of it as if it was already the object, That’s why they call it an entity. It’s easy to know that it’s not an object, it has no data, it’s saying it has a name, but it doesn’t say it’s "John". Only the object has the "John", the class is too abstract, you only know that there is a characteristic name in that possible object.

  • Class is a generalization or classification of an object. Object is something specific. This I understand. But the entity was confused, because you said that the class is a representation of the entity, said that the entity is a class within the code, but also said that the entity can be a person and in the computer will be an object. The entity is both the class and the object?

  • Yes, it depends from the point of view, at the moment of development is the class, at the execution is the object, but in real life is what generated it in the computer. Do one thing, forget entity :) It’s too conceptual and it’s something that’s causing confusion. Take it out of the equation and understand what’s important.

Show 7 more comments

1

Summary of the work:

  1. Class is a set of distinct objects, but with the same characteristics and behaviors.
  2. Object is an instance or model derived from a class. Therefore object is the representation of anything, real or abstract, of the real world that will be manipulated or stored by the system.

Browser other questions tagged

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