开发者

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

开发者 https://www.devze.com 2022-12-18 13:30 出处:网络
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

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 开发者_Python百科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?


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.


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.


It depends on why you're doing it. Are you doing it because it actually buys you anything or because you feel you should because you've seen this on some blog/whatever?

To me it sounds painful.

0

精彩评论

暂无评论...
验证码 换一张
取 消