4. Agenda
• What are Classes & objects
• Constructor and static blocks
• Access specifiers
• Static Methods
• Inheritance
• Abstract Class
• Interfaces
• Recommended Books to become level 3 Rockstar #AwesomeDev
• Q&A
5. Some House Rules
• Mute your mic
• Keep adding questions in Zoom Q&A Window
• No question is too small
• Questions will be answered at the end or on blog
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)
8. Class
• Class is blueprint or definition to create object
• It does not take any space in memory
• Consider it as guideline or contract detail
9. Object
• 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
10. Object Instantiation
Object creation includes three part
Rectangle rec = new Rectangle();
Rectangle - Declaration
new - Instantiation
Constructor - Initialization
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 ?
16. Inheritance
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
update inventory
• 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
child class.
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 ?
Database.executeBatch(yourclass);
Link here
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
shop
• Instance methods can access static but opposite is not true