The MVC paradigm
MVC is an architectural design pattern in modern software development that promotes the separation of an application into three components:
- An application's data storage (model)
- An application's user interface (view)
- An application's logic (controller)
The following diagram maps Salesforce's components to this architectural design:
This architecture is used a lot in software development because the isolation of data (that is, the model), user interface (that is, the view), and logic (that is, the controller) allows each component to be developed, tested, and maintained independently.
- Model: This is actually where your data is stored and can be used. To store data, you need objects or fields, and these are considered to be part of the model.
- View: This is whatever end users see and interact with; that is, what displays data to the clients or customers. This allows you to control how (and what) data is shown on the user interface. So, standard pages, page layouts, Visualforce pages, Lightning components, console layouts, and mini page layouts are all considered part of the view.
- Controller: This refers to the actual logic and actions that are executed when someone interacts with Visualforce pages, standard pages, or Lightning components. The controller is the link that binds the client side and the server side. It will mostly consist of Apex; this means that even when building Lightning components, you'll probably need Apex to get the data from the database on the server and pass it to the JavaScript controller. The new Lightning Data Service from Salesforce acts like a standard controller—it connects to objects and fields in the database without writing any Apex.
You could describe MVC like this—when you see a registration form (such as the Visualforce page developed on Salesforce), enter some information into the form, and then hit submit, the details are sent to a database and are saved into tables, columns, and rows (these are Salesforce objects and fields). Which data goes to what object and field in Salesforce is controlled by the logic defined in the standard and custom controllers.