I'm new to DDD and OO principles, sorry for my poor knowledge.
I have CustomerDTO and Customer classes.
I store all fields and properties in DTO class and use it as Base class for Customer class.
Main purpose of using DTO is to pass it to View. I've extended it in Customer class not to have duplication of properties.
Is it right way to do this or there's better OO solution?
I've read about AutoMapper, but I'd like to know, if there's alternative solution.
Many thanks for any kind of help.
I have personally never seen this approach. The reason you use a DTO is to seperate concerns between the DAL and the biz layer. It lets the business layer and the DAL change at their own paces with minimal side effects. All you have to do is change the mappings between the DTO and DO. If you inherit your DO from your DTO, whats the point of even having a DTO?
Quick answer: do not inherit your DO from your DTO. It might be easy now, but it may be a maintanence nightmare in the future.
PS Don't be afraid of Automapper. Its relativly easy to use.
This is a bad idea. Here are two reasons (there's probably a few more) why:
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