Salesforce coding lessons for the 99%
Finally, Apex tutorials for point-and-click admins! Written by a self-taught Google engineer.
  • Beginner Tutorials
    • Apex
    • Certifications
    • Career Info
    • Technical Architect
    • Visualforce
    • Videos
  • Apex Academy
  • Success Stories
  • About Me
  • Misc
    • Mailbag
    • Challenges
    • Links
    • Login to my Org
Follow @dvdkliuor SUBSCRIBE!

The Model-View-Controller pattern

February 11, 2015

Preface – This post is part of the Visualforce series.

Understanding the Model-View-Controller (MVC) pattern is essential to learning Visualforce.

HA! YEAH RIGHT!! There are only two reasons you need to know this mumbo jumbo:

  1. It’s on the Advanced Developer (DEV 501) certification test.
  2. Fancy conversation.

#2 happens to be important, so I’m going to teach you everything about MVC.

The Model is simply the underlying database. In Visualforce, it’s the collection of Salesforce objects and fields that we’d represent and modify in our page.

The View is the code that makes up our page’s UI. In our case, it’s all of our Visualforce, HTML, CSS, and Javascript code.

The Controller is the middle layer between the model and the view. It’s the Apex code that interacts with the database according to the view’s needs.

That’s really all there is to it! I still think they should’ve just called it the DUI pattern just to keep things simple. That’s database, UI, interface. Fancy conversation.

Why do we use the MVC pattern? By separating our page into three different components, we get a more modular codebase that’s ultimately easier to maintain and more scalable.

This kind of reasoning should sound familiar to you by now. It’s the same reason why we use objects in Salesforce. It’s also the same reason why we use classes in Apex. It’s also why your tires aren’t permanently attached to your car. See? Everything in this world revolves around objects!

Next post: Where to write Visualforce code!

4 Comments
Kevin in Oakland
March 6, 2015 @ 1:57 pm

Haha, the MVC questions keep popping up on my 401 flashcards, I even sketched out the diagram from Wikipedia. Mumbo jumbo! By the way just checked out those Google jobs, looks sweeeet. Better put a few more java books under my pillow. Have a great weekend David!

Reply
    David Liu
    March 7, 2015 @ 12:48 am

    Good luck Kevin in Oakland =)

    Reply
Anonymous
February 12, 2015 @ 4:35 am

Thanks David! This is great!

Reply
Ravi
February 12, 2015 @ 1:46 am

Glad to see new post David!

Please don’t forget to include the philosophy behind the each concepts going forward.

Many Thanks
Ravi

Reply

Leave a Reply Cancel reply

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


*

*

Theme: Simple Style by Fimply