Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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  {      public string PersonId;             public string Name;     public string Email;      public static bool IsValidName() { /* logic here */ }     public static bool IsValidEmail() { /* logic here */ } }   class PersonService {     private PersonRepository pRepository;      PersonService()     {         pRepository = new PersonRepository();     }      public bool IsExistingEmail(string email)     {         //calls repo method to see if email is in db     }       public Person GetPerson(email)     {         return pRepository.Get(email);     }       public void SavePerson(Person p)     {         if (Person.IsValidEmail(p.Email) && !IsExistingEmail(p.Email)         {             pRepository.Save(p);         }     }  }   class PersonRepository {     public void Save(Person p)     {         //save to db     }      public Person Get(string email)     {         //get from db     }      public bool IsExistingEmail(string email)     {         //see if email in db     }  } 

So which of the above classes are POCO, Domain Object, Model object, entity?

like image 600
jpshook Avatar asked May 27 '11 15:05

jpshook


People also ask

What is the difference between domain and entity?

Each domain contains a set of data related to a specific purpose or function (data access, exceptions, policy violations, and so forth). For a description of all domains, see Domains. Each domain contains one or more entities. An entity is a set of related attributes, and an attribute is basically a field value.

Are entities domain objects?

Entities represent domain objects and are primarily defined by their identity, continuity, and persistence over time, and not only by the attributes that comprise them.

Is entity and object the same thing?

An entity is something that exists in itself, actually or potentially, concretely or abstractly, physically or not. It needs not be of material existence. In computer science, an object is a location in memory having a value and possibly referenced by an identifier.

What are domain objects?

"a domain object is a logical container of purely domain information, usually represents a logical entity in the problem domain space ... In general, domain objects should know how to. recognize which [of their] references indicate aggregation and which ones indicate association. copy themselves.


1 Answers

My (non-standard) Layman definitions

  • POCO - Plain Old %Insert_Your_Language% Object. A type with no logic in it. It just stores data in memory. You'd usually see just auto properties in it, sometimes fields and constructors.
  • Domain object an instance of a class that is related to your domain. I would probably exclude any satellite or utility objects from domain object, e.g. in most cases, domain objects do not include things like logging, formatting, serialisation, encryption etc - unless you are specifically building a product to log, serialise, format or encrypt respectively.
  • Model object I think is the same as Domain object. Folks tend to use this interchangeably (I can be wrong)
  • Entity a class that has id
  • Repository a class that speaks to a data storage from one side (e.g. a database, a data service or ORM) and to the service, UI, business layer or any other requesting body. It usually hides away all the data-related stuff (like replication, connection pooling, key constraints, transactions etc) and makes it simple to just work with data
  • Service software that provides some functionality usually via public API. Depending on the layer, it can be for example a RESTful self-contained container, or class that allows you to find a particular instance of needed type.

Original answer

These are terms that are largely used in (Distributed) Domain Driven Design. They are not the same. The term model Object can be used as a synonym to the domain object.

Domain Objects. Objects from the business specific area that represent something meaningful to the domain expert. Domain objects are mostly represented by entities and value objects. Generaly speaking, most objects that live in domain layer contribute to the model and are domain objects.

Entity. An object fundamentally defined not by its attributes, but by a thread of continuity and identity. (Meaning it must have Id)

POCO. A simple object without complicated logic, usually it has just a few properties and is used with ORM or as a Data Transfer Object

class Person - Entity and POCO, instance of this class is Domain Object
class PersonService - Service
class PersonRepository - Repository

like image 139
oleksii Avatar answered Oct 05 '22 20:10

oleksii