How to apply SRP to user interface classes?

My application uses the DI infrastructure and, where necessary, you should practice a "program for the interface."

I am using constructor injection since I want to see the dependencies explicitly. But now, form class designers take too many parameters (> = 4, for example).

Question . Because user interface design is usually not SRP-bound, the Winform class may have constructor dependencies n. Do you like to leave them as they are, instead pass the proxy object, use the service locator ...? Also do you add “aspects” (logger, etc.) to each constructor, given that aop-framework is not used?

+3
source share
1 answer

There is no reason why user interface implementations should not adhere to SRP. Using templates such as MVP, MVC, or MVVM, class UI classDesigned for rendering and collecting data through the user interface. This is often best done with fairly passive data structures such as View Models.

The problem with the over-injection constructor should be resolved using refactoring to aggregate services .

Aspects are best addressed by applying the Decorator design pattern .

+4
source

Source: https://habr.com/ru/post/1786162/


All Articles