Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces


Published on

Path to code - Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces

Published in: Education
  • Be the first to comment

Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces

  1. 1. Path to Code Begin Your Salesforce Coding Adventure
  2. 2. Episode 3 Classes, Objects, Inheritance, Abstract Class, Interface
  3. 3. Sr Technical Architect Salesforce MVP 23 Salesforce Certifications @JitendraZaa Jitendra Zaa
  4. 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. 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
  6. 6. Badges Leaderboard
  7. 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. 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. 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. 10. Object Instantiation Object creation includes three part Rectangle rec = new Rectangle(); Rectangle - Declaration new - Instantiation Constructor - Initialization
  11. 11. Access Specifier Everything Public Private + Public vs
  12. 12. Demo 1
  13. 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. 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. 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. 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.
  17. 17. Demo 2
  18. 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. 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.
  20. 20. Demo 3
  21. 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. 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. 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) ?
  24. 24. Interface • Establishes contract that child class must follow • Can only have method definitions
  25. 25. Demo 4
  26. 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
  27. 27. Demo 5
  28. 28. Recommended Books
  29. 29. Level 1- Apex Design Patterns
  30. 30. Level 2 - Advance Apex
  31. 31. Level 3 - Enterprise Architecture
  32. 32. Q&A
  33. 33. Thank You