Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POCO vs DTO: Is it ok to partially hydrate a domain object?

Its often a requirement to have a domain object displayed in various ways on the UI; lists, search results, view and edit pages, as well as in headers, footers and popups. Typically you have several different "views" of the domain object, each with different fields displayed.

Most advice seems to be to use a DTO to get the data when you require a subset or superset. There is a lot of overhead in maintaining DTOs. Is it a bad approach to simply fill the properties of the domain object required for each scenario. For instance you might use a profile to say what properties should be included, eg:

service.GetDomainObjects(int listID, Profile.ListProfile); service.GetDomainObjects(string searchParam, Profile.SearchProfile);

like image 504
JontyMC Avatar asked May 05 '09 16:05

JontyMC


People also ask

Is using DTO a good practice?

Transfering data using Dtos between "local" services is a good practice but have a huge overhead on your developer team. There is some facts: Clients should not see or interact with Entities ( Daos ). So you always need Dtos for transferig data to/from remote (out of the process).

Is Poco a DTO?

Most importantly it is a well established fact that DTO is NOT a POCO. DTO is a data container, while POCO are objects as properties and are persistence ignorant (no get or save methods).

What is the difference between DTO and Domain object?

If using anemic data model (i.e. your domain objects don't have any logic), DTO and domain object can be the same object. No. Domain objects have no specific relation to any persistence. In simple words, they are parts to ensure the business logic required to run the application.

Is DTO value object?

DTO is a class representing some data with no logic in it.On the other hand, Value Object is a full member of your domain model. It conforms to the same rules as Entity. The only difference between Value Object and Entity is that Value Object doesn't have its own identity.

What is the difference between Poco and DTO?

A POCO is a BO (Business object). We can implement validation and any other business logic can occur here. POCO have state and behavior. It means ( layers) it does not depend on the design of the database, IE ., type of database, type of database object. What is DTO? Stands for Data Transfer Object, its Main purpose is to transfer data.

What is a poco data class?

It provides freedom to define an object model in which objects does not inherit from specific base classes POCO data classes, also known as persistence-ignorant objects, it refers to an object do not have any persistence concerns

What is the difference between a DTO and DTO?

First, let's define each term. A DTO is a "Data Transfer Object". It's an object whose purpose is to transfer data. By definition, a DTO should only contain data, not logic or behavior. If a DTO contains logic, it is not a DTO.

What is a poco (payload object)?

POCO is a concept that has been the source of many misconceptions because of the similarity with the concept of DTO (Data Transfer Object). POCO is a Business Object. It might have data, validation, and any other business logic that you might want to put in there. But there’s one thing a POCO does not have, and that’s what makes it a POCO.


1 Answers

For me what this comes down to is where you want the overhead to be, either you are going to have a set of different classes to represent your DTOs, or you are going to have a set of methods that each return the same domain object but with different fields being 'hydrated'.

A couple of questions I'd ask to help make the decision are:

  • what is the overhead in hydrating the entire object? Is the added complexity (of DTOs or partially hydrated objects) really worthwhile?
  • is anyone else going to be using your code? You don't to confuse people with paritally hydrated objects, DTOs might be more clear when people come to maintain your code.

I have a slight personal preference for DTOs as I feel the long term maintainance of your system will be easier. If your a one man band, or this is a one off throw away app, I can totally understand not wanting to introduce a bunch of extra classes that will clutter your code.

like image 75
thatismatt Avatar answered Sep 28 '22 03:09

thatismatt