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.

DFord
1,2502 gold badges16 silver badges31 bronze badges
asked Dec 30, 2017 at 15:45
1
  • 1
    have you got an example of where this service thign is suggested? Commented Dec 30, 2017 at 16:21

2 Answers 2

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

answered Dec 31, 2017 at 4:23
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.

answered Jan 3, 2018 at 11:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.