What is the difference between domain objects, POCOs and entities?

前端 未结 5 1887
萌比男神i
萌比男神i 2021-01-29 17:42

I was under the impression they are all basically the same. Are model objects also the same?

Right now, in my architecture, I have:

class Person 
{

            


        
5条回答
  •  日久生厌
    2021-01-29 18:08

    basically it comes down to internal logic

    1. Domain objects have internal domain logic for things like validation, etc.
    2. Model is basically a light Domain object, they know about the data they hold but nothing really about how it's going to be used
    3. Entities hold data and have some internal knowledge of where it came from, and where it's going to be saved, updated, etc
    4. POCO holds data and may have some internal knowledge about it's self, things like what is the total value of all the items in a property collection
    5. DTO is the simplest item of all, it just holds data and has no logic

    They are all basically used for the same thing, it's just how smart you want them to be

    according to your code sample The Person class would be a domain object or a model, the other 2 are a service and a repository. Domain objects, Pocos, models, dtos, etc. are used like messages, passed from one layer to the next, a service class like PersonService is a layer in the application and the same with the Repository class like PersonRepository. for a good over view take look at http://bob-the-janitor.blogspot.com/2009/07/n-tier-design-revisit-part-1-over-view.html in this case it's talking about using a data entity which is basically a dto

提交回复
热议问题