I use DTO’s, mom

In the time of ASP-Classic it was possible to use classes, but most of the data was transferred field by field. While developing you learn the good practices, like connecting classes not ‘wire by wire’, but by bundling all relevant data-fields in packages: models or DTOs (data transfer objects).
When to use a model or a DTO depends on the data used on both sides. A model can be used if the data structure is the same and when both classes share the same codebase. A DTO has advantages when the data structure is different, like database model versus the presentation model. A presentation model can use multiple models, like information about a person and information about courses. Also the presentation-state can be a model, like current page when showing a list or in case of a wizard. There will be some overhead by mapping models to a custom DTO for the communication between the classes, but in the end it will make the code better to read. Another example to use DTO’s is when the data needs to be transfered to a remote system. In that case the DTO must be serialized.

Reacties zijn gesloten.

Maak een gratis website of blog op WordPress.com.

Omhoog ↑