Stop using Data Transfer Objects (DTOs) in your code

Bending the Clean Architecture Principles

Anthony Trad
6 min readFeb 26, 2023

Introduction

Goals and objectives vary a lot depending on your organization's goals and constraints. When I was a consultant, I was essentially “outsourced” to help with a particular project for a short period of time. You get exposed to very diverse projects and different ways of doing things.

Then you realize that everything is debatable, what’s considered clean and efficient in one project is a no-go for another. The usage of Data Transfer Objects (DTOs) where a topic that constantly resurfaced throughout this period. I decided to share my experience around it and when it was causing more harm than good.

Here are my top 5 reasons why you shouldn’t use DTOs and what the alternative is.

What’s a DTO?

A DTO is essentially an object that bundles some data together. This packaged bundle is sent from one application to another or within the same application to transfer the data in a structured and easy way. Here’s a very basic example of a DTO:

// Before DTO
public void AddUser(string firstName, string lastName, int age, ...);

// After DTO
public void AddUser(User user);

public class User
{
public string FirstName…

--

--

Anthony Trad

Senior Software Engineer focused on .NET and the Cloud. Reconsidering major principles and patterns, ideas are my own.