7. Best Practices - 12 years in Coding
• Simplicity - easy to maintain and debug code in future
• aka KISS (Keep It Simple,Stupid)
• Write code keeping change in mind
• Functional Test Coverage is Angel
• Methods - as small as possible (20 line principle)
• DRY principle (Don’t Repeat Yourself)
• Class is blueprint or definition to create object
• It does not take any space in memory
• Consider it as guideline or contract detail
• Used to create custom data type
• It can contains variables or methods
• Objects are created using new keyword
• Object can be created on basis of class
13. Problem Definition
• Code to calculate Total Amount for number of products
• Code is written, tested and deployed
• Working fine from last 4 weeks
• Change requested by Client to give discount to some customers
14. What to do ?
Should we add if else ?
What if it breaks existing code ?
How much effort would it take to test everything again ?
15. What If ?
Wouldn’t it would be great that I should not change any existing code,
as its tested and working fine in production ?
If I can just add this new change without changing new code ?
Capability to create a new class which will contain functionality of
original class + Change existing functionality OR add some more
without impacting existing code.
18. Problem Definition
• There are different rule to calculate pricing of product
• Allow client to implement these rules as its unknown
• However, whatever the rule of pricing, during purchase it must
• In scenarios where, Some functionality are known and some are not
known, use abstract class.
19. Abstract Classes
• Contains some fully implemented method and some methods left
unimplemented with abstract method.
• Any class containing one or more than one abstract method known
as abstract class.
• Abstract classes cannot be instantiated using keyword new.
• In order to instantiate abstract class, it must be extended using
21. Problem Definition
• You are in global team where developers are spanned over
countries. Lots of changes in team.
• How to make sure that developer in your team working on some
plugin are forced to create all necessary methods.
22. Problem Definition
• How should Salesforce enforce you that below class must need to
have start(), execute() and finish() methods ?
23. Problem Definition
You have a CPQ product. How would you enable your customer to have
their own implementation of pricing but at same enforce them they
must have method named calculatePricing(List<Opportunity) ?
26. Static Methods / Variables
• Use method in class without instantiating / new keyword.
• Use static keyword to declare method or variable
• There is only one copy as compared to instantiated objects
• static method can access only static variable. Example of coffee
• Instance methods can access static but opposite is not true