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);
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).
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).
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.
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.
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.
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
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With