What is MVC? MVC or Model View Controller is object-oriented programming pattern. MVC pattern can use to developing a program with a programming language like PHP, Java, C, C++, etc. This pattern is useful because the code on this pattern can be reused to another function. That was significantly reduce developing time with the user interface.
The structure of MVC can be separated into three component.
The model component manages the data, rule, and logic structure of the program. This component can not contain user interface. The model represents transferred data between view and controller. For example, a customer is access user information view and manipulate the username with the name of the user model. The user object model will access the username database, and user object can update and manipulate the data in the database with customer wants.
The view is a user interface of an application. This component is used to bridge the interaction between the user and the application. An interface is showing what user can see and respond to the application such as menu, text, button, etc.
The controller is a connector between view and model. This component is ruled the incoming request access to a view and process the request to communicating between class in the model and render the output. So, the view component is not connected directly to the model component.
Advantage and disadvantage of MVC
- Reduce the developing time because the developer is not writing the same code twice. The code of an MVC pattern can be reused.
- The modifier of the code program is easier.
- Low coupling among model, view, and controllers.
- Simultaneous development because the developer is able to work in parallel on a different component. Developer team can be separated to back-end developer and front-end developer.
- A model component can have more than one or multiple of views.
- Code consistency can be hard if the developer is not making the same variable or a function in the different class or model.
- Complex code navigability because if we add the new layer of abstraction it will require the user to adapting.