Is Lightning Components built on the MVC pattern?

It is a very common question in most of the Interviews.

We know that the component itself is a view. We even know that MVC, or Model-View-Controller, design pattern is so common in web app frameworks. Is Lightning Components built on the MVC pattern?

In a word, no. There are similarities, to be sure, but it would be more correct to say that

Lightning Components is View-Controller-Controller-Model, or perhaps View-Controller-Controller-Database.

Why is “controller” doubled up in that pattern name? Because when interacting with Salesforce, your components will have a server-side controller in addition to the client-side controller. This dual controller design is the key difference between Lightning Components and MVC.

What’s the distinction between “model” and “database”?

In traditional MVC, the model is a programmatic abstraction (usually a class) between the underlying data storage (usually a relational database) and the rest of the application.

In Lightning Components, there’s no Apex class that directly stands in between @AuraEnabledcontroller methods and DML operations. But then again, sObjects are already an abstraction between your Apex code and the underlying storage layer. You can add calculation fields, validation logic, and even add fully programmatic behavior in the form of triggers.

Hope this will help you answer the question better!!

Chandra V [03/07/2019]

Leave a Reply

Your email address will not be published. Required fields are marked *