What is the difference between an Entity and a Model (MVC and the like)?

Asked

Viewed 516 times

5

In object orientation both are classes usually used to represent something that will be persisted (not that it is mandatory to persist), but what is the difference between them? Or are they different names for the same thing?

  • I believe that entity is the nomenclature that is used by the ORM. Hibernate for example. In my case... I now only use the model....

  • 2

    @Dnick that your answer seems to be just about controllers, has no direct relation to this question. Moreover, this is a question that is not applied to a specific language

  • @Costamilam, I agree. Comment removed.

1 answer

3


I’m imagining that in the context you’re using it’s the same thing with different names, and it depends a little bit on the discipline you’re adopting.

In MVC itself the term is model. I don’t see people who understand MVC using another term for it. And actually the word can be used in two contexts in MVC, you can say it’s a class is one of the models to be used in the model as a whole, I’m considering that it’s talking about the type of individual object and not the model as a whole. The model can also be a structure, the entire drawing with all individual models, i.e. model may be the term used to designate something that goes beyond the simple entity.

Entity is a term used in other contexts for the same thing. It is used in DER diagrams, either in Orms or mainly in DDD. But it is the class of the object you want to declare to mount the general model.

As people learn everything more or less begin to mix the terms and contexts, then it becomes a mess and "nobody" understands what each thing means, and most do not worry that they are confused. There comes a point that everyone is teaching wrong. A case that I always talk about is about field and attribute, almost everyone uses wrong because there are many books teaching wrong.

I did some research on what people have been writing around, and there’s a lot of confusion, a lot of nonsense about the terms because they can’t clearly define his boundary. So I can’t guarantee that my answer is an absolute truth, it can be disputed, but it was thought out and has criteria.

For example I don’t fall for the bullshit of saying that a model It involves persistence (I say this because I’ve seen a lot of people talking like this in the research and I assure you this is wrong, so you may have learned wrong). It is common to involve, but it does not need to. The model never defined where the die of that object comes from or goes, it could be a stream, could be ephemeral.

Entity involves persistence? I do not know, in this case I will not guarantee. The fact is that I have never seen anywhere that it is a native term of MVC, so if it is used in another context, though together with MVC or even superimposing on the same mechanism (the class of the defined object), it will depend on that context. If the entity is being used in the context of an ORM then I think persistence makes sense.

So the same class is being used for two different implementations (MVC and ORM) and so it gets a different name in each case, even if it’s one thing.

And I understand that it does not need to have a one-to-one relationship between the model and entity, although it is the most common.

  • 2

    Whoever gave me the negative could tell me what’s wrong for me to fix, so everyone benefits and learns. Since the person knows something’s wrong it’s not fair to the community to keep it to themselves.

Browser other questions tagged

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