MVC is a well known software architecture paradigm use to organise code in a manner that is understandable and relatable between any person reading the code. Software patterns are a great method to avoid spaghetti code as the code increases. At MVC’s core there are 3 main objects to consider when one uses this pattern.
The model represents the data of an application. Data within these models are explicitly modified and manipulated by their own models. When classifying a model, it’s a good idea to think of it as an item that can have particular characteristics or attributes that make it unique. Here’s some examples of what a Model could be
A weapon in a game
A CPU in a PC
A fabric/material on a piece of clothing
Between models there can be database relationships can be defined between models such as one-to-one, one-to-many, etc. Relationships are a link between models. They allow each model to communicate and organise data following a set a rules defined by the relationship.
a post can have many comments (one to many)
a post can have many likes (one to many)
a like must be associated to one comment (one to one)
a comment must be associated to one post (one to one)
employees belonging to a company (many to one)
The view is what all users see within the application. It manages the interaction between the user and the controller. Though it may seem the view interacts directly with the model, this is not the case. In order to preserve the pattern, the view is decoupled from the model and the controller must directly influence the model’s data whenever user action is applied then the view is updated by the controller once the data has been processed.
The Controller is a medium between the view and the model. It updates data between the view and the model and interacts with he view layer when a user applies an action and the model notifies the controller when data has been manipulated. Thus is acts as the main management between the two layers.