Question

Can someone explain these 3 concepts and the differences between them with respect to an MVC framework along with an example. To me these appear almost equivalent, and it seems they are used interchangeably in some articles and not in others.

Was it helpful?

Solution 2

The terms are a bit vague I agree. I would use domain to refer to the business area you are dealing with. Like banking or insurance or what not. Then you have domain models. These are the things you deal with in that business domain, like for domain of banking you have accounts, customers, transfers etc. I would use term entity for referencing the class/POJO or the persisted / concrete version of a model.

What probably confuses you here is that in the term MVC, the model is a concrete thing, but it references the data model used to represent some presentation in a web GUI so don't get that mixed in with the above explanation.

OTHER TIPS

The terms you are confused about are: "domain objects", "domain entities" and "model objects". While usually used interchangeably, the domain entities and model object can also be instances of active record pattern (basically: domain objects with added storage logic).

In ordinary domain object there is no storage logic. It gets handled by data mappers.

The term "model objects" comes from Fowler's books (read PoEAA for more details), and, IMHO, is part of the confusions MVC, because the entire model is an application layer (MVC consists of it and presentation layer), which contains those "model objects", which are usually dealt with by services (in that image, the model layer is all three concentric circles together).

I much prefer to use "domain object" term instead.

The term "domain entity" (or "entity object") is usually used when author implies that the object is a direct representation of a storage structure (more often - a database table). These are also almost always implementations of active record.

P.S.: in some articles you would also see term "models" (plural). It usually is not directly related to MVC design pattern, because it talks about Rails-like architecture, where "models" are just active records, that get directly exposed-to/created-by controller.

.. not sure whether this confused you more

For the record. In practical purpose, domain and model are the same, while entity is also a domain/object that would be used to store in the database.

Some people are tried to re-explain such topics but none of them are canon.

The difference is that, in the world of Java, Domain is more used, while in the world of C#, Model is used (and MS encourages his use) but its just convention and you can use both.

In the same, concept, Value Object (VO) is used by the people of Java, while DTO for the people of C# even when both are practically the same. Also POJO (Java) vs POCO (C#), Packages (Java) vs NameSpace (C#), Setter and Getter (Java) vs Encapsulation (C#)

Both domains and models are classes. How the class is use distinguishes if it should be classified and put in a domain or model folder. If the class is going to be used ONLY in the view, put it in the model folder. If the class is mapped to a database object, then put it in the domain folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top