Functional decomposition
Usually, a developer starts building a trigger or page controller and ends up writing all the business logic within the trigger or controller itself. It is definitely easy and fast but hard to maintain.
Say, for example, we have to develop a Visualforce page with the custom functionality of generating an invoice. So, we begin our controller, as follows:
public class GenerateInvoiceController{
public Invoice__c Invoice {get; set;}
//generate invoice
public void generateInvoice(){
if(validate(Invoice )){
insert Invoice ;
}
else{
// handle validation errors
}
}
//validate invoice
public Boolean validate(Invoice__c Invoice){
Boolean isValid = false;
// validation logic
return isValid;
}
...