Modifying Sharepoint Application Pages in the RIGHT WAY

So many time we come across scenarios where we need to modify the functionality Sharepoint Application Pages (for those who are new to sharepoint Application Pages are physical pages residing the Layouts folder) Microsoft recommendation is not to modify these as the modifications can get overwritten in the next service pack or a patch….