Controller reuse in MVC

In the MVC pattern, the controller is the least repetitive compared to the other two aspects. Now let me say that I have an application (say, for Ordering Pizza) that is available for both a web application and a mobile application (say, iPhone). Therefore, in this case, I think that the model (or data) can be reused. The view cannot be reused.

But as for the controller, is it possible to repeat something? Say, if I already have a working web application, is it possible to reuse the controller logic for a mobile application? Besides, what exactly is and where exactly is the “business logic" located in MVC?

+3
source share
1 answer

The controller calls the service level. The service layer uses the model to conduct business logic. A controller never contains business logic. He should delegate work only to the service level. I consider the service level as a part that the domain model provides, we can say that this is the “Model” in MVC.

However, I do not think that the MVC structure really cares if the controller is reused or not. An important part is the model, which should not be changed because the service level code is reused. In addition, if we write our code correctly, the controller will be a very thin layer, and reuse should not be a concern.

- ? , , . , - , .

, , -.

+6

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


All Articles