Why in the MVC design pattern what 3 components?

I understand why a seperate View.
1. When the interface changes (but not logic) are not affected by classes responsible for application logic
2. For GUI it is impossible to write tests, so highlighting the code responsible for polzovateley interface in separate classes, it is possible to use tests to Model and Controller
3. In theory, simplify the porting of the application under a different GUI framework, as you will have to rewrite only View

But I do not understand why to separate Model and Controller.
After all, the rest of the application is some data plus interface to them. It fits into the paradigm of the PLO. Data is private members of a class, an interface is public. To read and change data only through the Controller. The data is the Model.

What I am mistaken? What would I encounter if the Model and Controller are combined into one entity. What will I get if I try the same to separate Model and Controller into different entities which will interact using some interface? Although how to divide them?
September 26th 19 at 06:13
1 answer
September 26th 19 at 06:15
What you describe - approach using fat controllers. Discover the wonderful world of Service-Oriented Architecture. Even as models, they are the same domain model, it's just a representation of the data. For the preservation of data and its processing, validation, etc. answer services. The controllers also can be presented in the form of services, and the challenge will only check whether the user has access to the operation that actually needs to be done and Thus the controller may not have a clue about where data is stored, how it is processed... It just looks that the user can save the data, transmit user data to the service, that saves....

In short something like that.

Example:
class User
{
 private $id;
 private $email;
 private $password;
 private $enabled;

 public function getId() {...}
 public function getEmail() {...}
 public function setEmail($email) {...}
 public function getPassword() {...}
 // for password hashing meets service model to know anything about it should not. 
 public function setPassword($password) {...} 
 public function isActive() {}
 public function activate() {}
}


controller example
/**
 * @Route("/users")
 * @Method("POST")
*/
public function createUserAction(Request $request) {
 if (!$this->get('security.context')->isGranted('ROLE_ADMIN')) {
 throw new AccessDeniedException();
}

 $user = new User();
 $form = $this->createForm(new UserForm(), $user);
$form->bindRequest($request);
 if (!$form->isValid()) {
 // save errors to session, redirect 
 return $this->redirecti(...);
}

 $user = $form->getData();
$this->get('app.user_manager')->createUser($user);

 return $this->redirect();
}

Find more questions by tags MVC