Skip to main content

Classes, Inheritance and Overriding in SalesForce


Classes

In a class we have two types of numbers
  • Static means belongs to class & non – static means belongs to object
  • Static number methods can access the static and non static  data members
  • Non –static member methods can access the static and non –static data members
  • You can access the static methods through
Classname. Method name
  • You can access the non static methods through
Object name. method name;
                                 ↓
Object handle. method name;
Types of methods we perform all over Apex are
1.Constructors  → [DC, PC]
2.Setters
3.Getters
4.Operations (actions) →  in apex
When to use static & non static method as?
→ The non static method is used w.r.t the object what you perform
→ The static method is used independent of the object what you perform
Accelerate Your career with Salesforce Training and become experts in Salesforce Enroll For Free Salesforce Training Demo!
Memory Belongs To Static & Non Static  
 
  • Only one single copy of memory for static memory  method . It also contains no. of objects,
Inheritance
  • Routing of one encapsulation of performing elements to build another encapsulation
  • The main advantage is reusability of features
  • Because of these features oops are highlighted
Q: Why do we need inheritance?
It enables better and faster development of new features with the ability to reuse and modify the existing features
Ex:
Class account{
Name
Number
Balance
Class SavingAccount{
Name
Number
Balance
Min bal
Class Current Account{
Name
Number
Balance
Min bal
Own bal
Constructor
Setter
Getter
showBal
withdraw
deposit
}
Constructor
Setter
Getter
showBal
withdraw
deposit
}
Constructor
Setter
Getter
showBal
withdraw
deposit
}
  • Saving account = accounts + mm bal
  • Current account = SA + owner name
                 = account + min Bal + owner name
To work with inheritance we require at least two classes, but all previous features are explored through a single class
Out of these two classes a class which contains the essential features and provides its members for another encapsulation is known as parent (or) base (or) super class
The class which reuses the existing class members or depends on the other class for its existence  is known as child (or) derived class (or) subclass
Explore Salesforce Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!


Syntax For Inheritance:
Class parent{
}
Class child extends parent{
}
Extends
(It is a key word)
Nothing but visa
  • The parent members are coming to child class for visiting through visa
Class parent {
Private integer pm1: → security
Private integer pm2: → reusability
Protected integer pm3: → security + reusability
Scope: Within the class and related classes
Types of classes in inheritance
1. Final
2. Virtual
3. Abstract
Every class is final by default in inheritance
Class typeWhat we’re in a classObjects creationreversible
Final
Data members
member methods
def’s
We can create
objects
Not reversible
Virtual
Data members
member methods
def’s
We can create
objects
Reversible
Abstract
Data members
member methods
def’s and also
method prototypes
construct
No object can
be created
Reversible

Virtual → [Class, Method]
Override  →  method  ↓
Years strike off older one work with new only
→     Only virtual and abstract methods can be overriden
→     Abstract methods can only write in abstract classes

Overriding

It is an object-oriented programming that enables the child class to provide different implementation for a method that is already implemented in its parent class.
  • This is possible through only inheritance
  • Multiple methods containing same name, same signature is inherited (virtual) and another is originated (over ride) in the child class
Q.Why over riding?
If a parent class method serves in the purpose of  a child class, do not override (or) else to make the child over the ride
Abstract Class:
  • No object can be created for this class
  • An abstract method can exist only in the abstract class
  • An abstract method is declared only to enforce the implementation of the method
  • Any class that inherits an abstract class must definitely override the parent abstract Method, or else the compiler run through an error
  • For the actions performed by the child class, we go to abstract classes
  • The parent does not need anything to override if any class is defined as an abstract class
Class Typemethod definitionMethod prototypeCreate objectsinherited
Final_/×_/×
Virtual_/×_/_/
abstract_/_/×_/

Class Typemethod definitionMethod prototypeoverrideClass type
Final_/××Final
Virtual_/×_/Virtual and abstract
abstract×_/_/abstract

Key Words:
  • Extend
  • Protected
  • Virtual
  • Abstract
  • Override
Q.When to make a method final?
  • If its implementation is perfect and does not require any further modification, use, make it as final
Q.When to make a method virtual?
  • A method is implemented for a specific purpose and can be modified for any other purpose.
Q.When to make a method abstract?
  • Whenever we can’t decide  the implementation and need to carry out it at a later point of time, then we make it abstract
Ex:
Public virtual class parent {
Private integer pvt_mem;
Protected integer ptd_mem;
Public integer pub_mem;
Public virtual void gets values (){
System. Debug (‘Pvt Mem’ +pvt_mem);
System.debug(‘ptd Mem’ +ptd_mem);
System. Debug (‘pub mem’+ pub_mem);
}
}
Public class child extends parent {
Private integer pvt_ch_mem
Public override void get values () {
System. Debug (‘Pvt ch Mem’ + pvt_ch_mem);
}
}
Global class test {
Public static test method void main () {
Parent p1= new parent ();
P2.get values ();
Child c1= new child();    c1.gets values ();
}
Ex:
Public abstract class parent {
Public abstract void gets values ();
}
Public class child extends parent {
Private’s integer pvt_ch_mem;
Public override void get values () {
System. Debug c’ Pvt.Mem’ + pvt_ch_mem);
}
}
Public class test {
Public static test method void main () {
Child c1 =new child ();
C1.gets values ();
}
}
Parent p1 = new  child ();
Parent handle can refer to the child object
Child c1 = new parent ();
Parent object doesn’t handle the child
→ Child handles can’t refer to the parent object

Comments

Popular posts from this blog

Blue Prism Free Totorial

Enterprise Robotic Process Automation Software RPA  Software Robots that Automate Business Processes across your entire Enterprise Robotic Process Automation (RPA) is an emerging technology of process automation based on Software Robots/Artificial Intelligence workers. RPA is the significant technological innovation of screen scraping. RPA provides new platforms which are sufficiently mature, scalable and reliable for use in large enterprises. Robotic Process Automation delivers profits by enhancing the reliability across numerous industries and organizations. These software robots interpret, trigger, compare, acquire results, and communicate with other systems just like a human. They perform a vast range of repetitive tasks without tire and mistakes. These robots even integrate readily and are easy to maintain. Interested in mastering  RPA Training ? Enroll now for FREE demo at   Tekslate . Empowering your Business with RPA Incorporating RPA to handle business p

Selenium interview Questions

If you're looking for Selenium Interview Questions and Answers for Experienced & Freshers, you are at right place. There are a lot of opportunities for many reputed companies in the world. According to research Selenium has a market share of about 27.7%. So, You still have opportunities to move ahead in your career in Selenium. Mindmajix offers advanced Selenium Interview Questions 2018 that helps you in cracking your interview & acquire your dream career as Selenium Developer. Top 35 Selenium Interview Questions And Answers : The entire set of Selenium interview questions is divided into three sections: Basic level Advanced level TestNG framework for Selenium Accelerate your career with Selenium Online Training and become an expert in Selenium. A. Basic Level  – Selenium Interview Questions 1. What are the significant changes in upgrades in various Selenium versions? Selenium v1 included only three suite of tools: Selenium I

MuleSoft Interview Question And Answers

If you're looking for MuleSoft Interview Questions for Experienced & Freshers, you are at right place. There are lot of opportunities from many reputed companies in the world. According to research, MuleSoft has a market share of about 5.9%. So, You still have an opportunity to move ahead in your career in Mule ESB. Tekslate offers advanced MuleSoft Interview Questions that help you in cracking your interview & acquire dream career. Learn how to use Mulesoft, from beginner basics to advanced techniques. Enroll for Free  Mule ESB Training   Demo! Q. What is Mule ESB? Mule ESB is a Java-based enterprise service bus (ESB) and integration platform, developer can connect their application with ESB. Mule use service oriented architecture. Apart from of the different technologies the applications use, including JMS, Web Services, SMTP, HTTP. The advantage of ESB, it’s allow communicate different application. Messages can be any format SOAP to JSON. Mule ESB Development pr