Maintaining the Single Responsibility Principle (SRP) with UIViewControllers

Following Apple's principles, I create one subclass of UIViewController on the screen of my iPhone application. However, I consistently find that these classes become very large, both in terms of strict lines of code and the number of member variables.

By definition, they are ultimately responsible for a number of different problems (for example, the kind of life cycle, mediation between views and models, sometimes touch processing, control logic, managing alerts and other user interface states).

This not only violates the principle of single responsibility, but also leads to large pieces of code that are almost impossible for a unit test.

What responsibilities / problems do you tend to divide into new classes? What types of responsibilities do you consider to be good candidates for pure separation in the case of subclasses of the UIViewController?

+3
source share
2 answers

This is an interesting question, and I am also struggling on how to separate responsibility. It all depends on the context, but since testing subclasses of the UIVieController can be a pain, I try to move as much as I can into model classes. In the spirit of Skinny Controller, Fat Model .

, , , . .

, . , .

.

UIViewController *detailController = [self.controllerFactory controllerForItem:item];
[self presentModalViewController:detailController animated:YES];

, unit test, .

+1

, , , Java, . , , , . , , , .

0

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


All Articles