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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s