1

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)

  1. View sends new input to Controller
  2. Controller sends the request to Model with data it recieved to one central method of Model
  3. Model takes this data and internally processes it with its methods, and returns the data to controller
  4. Controller tells the View to update was completed and to update the View
  5. 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

  1. Controller sends the data to Model
  2. Model calls respective Service to process the data
  3. 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.

  • 1
    have you got an example of where this service thign is suggested? – Ewan Dec 30 '17 at 16:21
3

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.