Understanding the Model View Controller pattern

The MVC pattern separates applications into three main layers: models, views, and controllers. One of the benefits of this pattern is the separation of concerns (SoC), which can also be described as the Single Responsibility Principle (SRP), which makes it possible for us to develop, debug, and test application features independently.

In software engineering, it is considered good practice to keep similar functionality as a unit. Mixing different responsibilities in a unit is considered an anti-pattern. There are other terms, such as heavy coupling, that describe a similar scenario where, for example, changing one aspect of a class requires changes in others to create a ripple effect. To avoid this effect, concepts of SoC and SRP were coined and are encouraged as they greatly help in unit testing as well, making sure the required functionality does what it purports to do.

When using the MVC pattern, a user request is routed to a Controller, which will use a Model to retrieve data and perform actions. The Controller selects a corresponding View for the user while providing it with the necessary data from the Model. There is less of an impact if a layer (for example, the Views layer) changes since it is now loosely coupled to the other layers of your applications (for example, controllers and models). It is also much easier to test the different layers of your applications. In the end, you will have better maintainability and more robust code by using this pattern:

It must be mentioned that this is a simplistic diagram and shows the main concentration areas for unit testing and integration testing. A better understanding of each component and how it relates to the others will be provided in the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.51.36