Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc am i using too many classes for my models?

I am creating an n-tier wep app with asp.net mvc which calls a stateless service layer.

so, in addition to the "model" that the service layer handles with an ORM, I have a DTO for each model class which maps to a specific controller. Then for each DTO class I have a UI model class, which i populate with appropriate data from the DTO then use with the view. Then, in the controller on post, i send information from the UI view to the service layer. does that sound right?

like image 423
robert j Avatar asked Jan 22 '23 16:01

robert j


2 Answers

Yes, that sounds like you are following the Single Responsibility Principle instead of munching everything together in God Classes.

You can rarely have too many classes, but the most important point is not the number, but the clear demarcation and encapsulation of responsibilies.

From the short description given, it doesn't sound completely off.

like image 191
Mark Seemann Avatar answered Feb 20 '23 06:02

Mark Seemann


Yes - it does sound right. Only - i would use ORM like NHibernate, that supports POCO in order to drop service DTOs.


On the other hand - it's all about context.

like image 39
Arnis Lapsa Avatar answered Feb 20 '23 04:02

Arnis Lapsa