Let us look at an interview question that revolves around Apex Classes.

Standard Controllers

One of the main advantages of Salesforce is when we create a Sobject we get access to something called a Standard Controller.

Irrespective of the object being a standard object and custom object we get access to it.

<apex:page StandardController="Account">

</apex:page>
Standard Controllers in Apex

In a standard controller, we will be getting access to 9 methods and we can use them to perform some standard out-of-the-box functionalities.

Custom Controllers

If I were to override the methods with my own custom functionality or implement a new method that not part of the 9 out of the methods then I need to create a Custom Controller.

<apex:page controller="CustomController">

</apex:page>
Custom Controllers in Apex

Extensions

An Apex Custom Controller and Apex Extension both are one and the same with the only difference that in an Extension we will be having a mandatory one argument constructor which is not the case with a Custom Controller.

public with sharing class CustomExtension{

	public void foobar(ApexPages.StandardController controller){
    
    }
}
Extensions in Apex

If I want to associate a Visualforce page with more than one Apex Class then we need to make use of an Extension.

The advantage of using an Extension is we can have up to 5 extensions by separating each of them with a comma.

If a method is implemented in both the Extensions, the extension that comes first that has the method implementation gets the priority and gets invoked.

<apex:page controller="CustomController" extensions="CustomExtensionOne,CustomExtensionTwo,CustomExtensionThree,CustomExtensionFour,CustomExtensionFive ">

</apex:page>
Using multiple extensions in a Visualforce page

Hope this helps!