These days, all I hear is how MVC should contain additional layer called services, turning it into SMVC. But to me, it seems like too much of a decoupling and instead want to engineer my app something like this (example for changing user name)
- View sends new input to Controller
- Controller sends the request to Model with data it recieved to one central method of Model
- Model takes this data and internally processes it with its methods, and returns the data to controller
- Controller tells the View to update was completed and to update the View
- View updates itself with data given by Controller
I have been told that Model should not directly work on data either and instead should use Service layers to handle the bussiness logic, so the flow would change like this
- Controller sends the data to Model
- Model calls respective Service to process the data
- Model updates the data after Service processes them Rest is the same
For me, the first solution seems more elegant and the later seems like making a Model another Controller with data relying on Services, which is kind of weird logic and adds another layer of complexity to the whole app.
-
1have you got an example of where this service thign is suggested?Ewan– Ewan12/30/2017 16:21:07Commented Dec 30, 2017 at 16:21
2 Answers 2
The extra layer allows to be independent with respect to the data layer. That introduces flexibility, allowing a number of things, including:
- unit testing business logic, without data layer technology dependency
- support multiple data layers
- move to different data layer technology
- etc
Martin Fowler is much better at explaining this: https://martinfowler.com/bliki/PresentationDomainDataLayering.html
I would suggest reading this answer on How essential is it to make a service layer? It states several reasons why you should implement a Service Layer. If you think that you don't need one, probably your use case is too simple.
Explore related questions
See similar questions with these tags.