Do You Really Need a Data Transfer Object?

  Рет қаралды 6,461

SingletonSean

SingletonSean

Күн бұрын

Пікірлер: 20
@zwatotem
@zwatotem 11 ай бұрын
I like that this channel actually doesn't just blindly teach whatever is widely considered "the best practices" as a given truth. Instead it asks these questions that I also frequently have, challenging the authorities with well thought out arguments.
@SingletonSean
@SingletonSean 11 ай бұрын
Thanks! I feel like the "reason why" behind best practices often gets lost, even though that's an important part to understanding a best practice
@prakticamode
@prakticamode 10 ай бұрын
You are a gem on youtube. Am developing an application that will have to have its datasource migrated (no concrete details yet) so i am now expanding the project with DTOs just to be prepared. It also helps clean up the original object model nicely. Love your videos.
@dono42
@dono42 11 ай бұрын
At the start of new projects I often try to get away without needing to define DTOs. However, except for the most simple projects, as the complexity grows I eventually need to refactor and define DTOs. In hindsight I often regret not defining DTOs straight from the beginning.
@jrosimo098
@jrosimo098 11 ай бұрын
Im going into my first year as a Software Engineer and im now only learning about DTO, finally i get to understand it. Thanks Sean!
@erikjlee1
@erikjlee1 11 ай бұрын
Great video Sean. If you adhere to Model Driven Engineering/Architecture concepts, your domain model is the DTO. In the utility industry, IEC CIM is a domain model that doesn't define behavior, only structure. However, IEC61850 defines both behavior and structure for it's more specific use cases. Like you said, "it depends." But personally I would not want to maintain two large models. Simplicity is key IMO.
@michaelkhalsa
@michaelkhalsa 11 ай бұрын
Another benefit is that you can close the db connection more quickly with a dto. When populating tens of thousands of dto objects this can be significant. In addition simple methods can be added within your database layer to quickly populate a dto by index, rather than names from your sql results, which is dramatically faster for large queries. The same to dto methods which take a data reader can be reused for calls returning a single row or thousands. Its a touch more work than using an orm to handle all the mapping, but benefits are tangible. .
@edpoitras420
@edpoitras420 11 ай бұрын
The content in this video is excellent and gives good examples as to why you should or should not use the dtos thanks a lot
@TheTigerus
@TheTigerus 11 ай бұрын
Typical SQL database has names of columns only with lowercase letters and words are separated with underscore. When I'm using Dapper, i need my property to have the same name as column name, though it can be uppercase. There is no way I'll have variables named like: Some_Variable in my C#, so I'm using DTOs to fix the problem
@vincentotieno9197
@vincentotieno9197 11 ай бұрын
Mmh... finally I have some clarity on the differences between domain objects and DTOs, and when I should use them. Thanks for the clarification.
@TornTech1
@TornTech1 11 ай бұрын
Wait, what? Iv always used “Models” for my binding of data against SQL through stuff like EF… a DTO for me, is something I expose out of my repository or something so it doesn’t tarnish the model. Like I might get a PERSON (Model) from EF which contains all this stuff About the person but would expose a BasicDetailsDto which may only care sboit the name and age of the person.. that way I’m not exposing too much and I’m not coupled to my Data model so they can grow separately. It sounds like from the video (Iv not finished it yet TBF) that you see models and DTO’s the other way around… What do/would you use on your DbSet in an EF DbContext for example?
@DanimoDev
@DanimoDev 11 ай бұрын
Great video Sean, and you are right, it depends, I don't think there is a definitive answer. Personally, I lean towards DTO's, they can add complexity for sure and it's another thing to maintain, but they act as a contract for incoming/outgoing data. With DTO's, the I/O data contract doesn't have to be the same as the apps domain models, and having that separation and the flexibility it gives can save some pain later. I suppose it really does depend on context and preference though, sometimes it is overkill for a really small app and/or where you are almost certain the data will always maintain the same shape in/out the app. However, in other cases you might be using a 3rd party or an existing service and will need to reshape/map data both ways.
@pging8328
@pging8328 5 ай бұрын
what is a "domain" object?
@leduchoan
@leduchoan 11 ай бұрын
DTOs are good, however they somehow quite hard to manage cause of reflection.
@SingletonSean
@SingletonSean 11 ай бұрын
Agreed! Sometimes the trade-off is worth it though
@nahomb2784
@nahomb2784 11 ай бұрын
How about using composition instead of DTO?
@SirBenJamin_
@SirBenJamin_ 11 ай бұрын
Hang on - isn't this the guy from American Pie?
@SingletonSean
@SingletonSean 11 ай бұрын
I literally get this same exact comment in real life at least 5 times a year, lol
@SirBenJamin_
@SirBenJamin_ 11 ай бұрын
@@SingletonSean 😁😁👍🏼👍🏼
@georgeokello8620
@georgeokello8620 11 ай бұрын
Now that I see it, I can’t unsee the image in my head
Simplify Configuration via Polymorphism
14:28
SingletonSean
Рет қаралды 2 М.
Is an ANEMIC Domain Model really that BAD?
10:36
CodeOpinion
Рет қаралды 18 М.
Use Data Transfer Objects (DTOs) in .NET the Right Way 🚀
6:48
How To Use DTOs In .NET REST APIs
14:18
Julio Casal
Рет қаралды 21 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,8 МЛН
Event-Driven Architecture (EDA) vs Request/Response (RR)
12:00
Confluent
Рет қаралды 179 М.
5 Rules For DTOs
17:56
Ardalis
Рет қаралды 46 М.
Why use DTOs (Data Transfer Objects)?
7:23
CodeOpinion
Рет қаралды 74 М.
Is an Anemic Domain Model an Anti-Pattern?
9:54
Milan Jovanović
Рет қаралды 23 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 222 М.
Data Transfer Objects - What Are DTOs - Full PHP 8 Tutorial
13:03
Program With Gio
Рет қаралды 43 М.