0% found this document useful (0 votes)
9 views12 pages

Naming Conventions - CallByVal - OOPS

Apex Naming Conventions - CallByVal - OOPS

Uploaded by

lsrinivas.rpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Naming Conventions - CallByVal - OOPS

Apex Naming Conventions - CallByVal - OOPS

Uploaded by

lsrinivas.rpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Naming Conventions:

- Apex is case in-sensitive language


- Class name should start with capital letter
- Variable names should start with small case and proceed with camel case
- Method names should start with small case and proceed with camel case
- You can not start var, methods and class names with numbers, but you can use it in-between
or at the end of the names
- You can not use special characters for your class or method names except underscore
- Apex will not allow duplicate class names and var names
- Final variables should be written in CAPITAL case

/**

* Class name should be written in PascalCase

* Each word should be capitalized

* Note: Always give meaningful name to your class

* */

public class NamingConventionsDemo {

// Variable name should be written in camelCase

// First world should be all in small case, and each word after that should be capitalized

// Note: Always give meaningful name to your variable

String superSecretKey = 'Secret_Key';

// Constant variables should be written in CAPITAL CASE

final String MY_FINAL_VARIABLE = 'DUMMY';

/**

* Method name should be written in camelCase

* First world should be all in small case, and each word after that should be capitalized

* Note: Always give meaningful name to your method

* */
public void demoFunction(){
String superSecretKey = 'Secret_Key';
}
}

Pass by value and Pass by reference:

“Pass by value” means when a method is called, a second copy of the parameter variable is made in
memory, and this copy is passed to the method as a parameter. This copy can be modified in the
method, but the original variable in the caller is unchanged, and the changes to the copy are lost
upon return.

Calling or invoking a method by passing a primitive value is called as Pass by value or call be value.

“In Apex, all primitive data type arguments, such as Integer or String, are passed into methods by
value.

“Pass by reference” means when a method is called, that actual variable is passed to the method.
non-primitives types classes and objects are passed by reference
Calling or invoking a method by passing the reference variable is called as Pass By Reference or call
by reference

public static void incrementValue(Integer num){


num++;
System.debug('inside method value' +num);
}

public static void main(){


Integer myNumber =10;
incrementValue(myNumber);
System.debug('outside method value' +myNumber);
}

public class CustomObject{


public Integer value;
public CustomObject(Integer val){
value = val;
}
}
public static void main1(){
CustomObject myObject = new CustomObject(60);
updateObhectValue(myObject);
System.debug(' --- Inside Method value-by ref-'+myObject.value);
}
public static void updateObhectValue(CustomObject obj) {
obj.value+=100;
System.debug(' --- Outside Method value-by ref-'+obj.value);
}
public void mainValueMethod(){

String websiteUrl = 'www.amazon.com';

System.debug('Before value call ' + websiteUrl);


passByValueCall(websiteUrl);
System.debug('After value call ' + websiteUrl);
}

private void passByValueCall(String websiteUrlValue){


websiteUrlValue = 'www.salesforce.com';
//Pass by Value Call
}

public void mainReferenceMethod(){

Account a = new Account();


a.Name = 'Test Account';
a.Website = 'www.amazon.com';

System.debug('Before reference call ' + a);


passByRefCall(a);
System.debug('After reference call ' + a);
}

private void passByRefCall(Account a){


a.Website = 'www.salesforce.com';
//Pass by Reference Call
}
 Encapsulation – Encapsulation is the ability to bind data and behaviour together.
For example, a capsule is wrapped with different medicines in it.
Abstraction – The process of abstraction in Apex is used to hide certain details and only show the
essential features of the object. Hiding internal details and showing only the functionality is known
as abstraction. Eg: Driving a car, using an ATM
Inheritance – In object-oriented programming, classes can exhibit a property of acquiring some
common traits and states from others classes. In other words, it is defined as the mechanism by
which the child class gets to inherit the features i.e., fields and methods of the parent class. It offers
code reusability and also assists in runtime polymorphism.
Polymorphism – Polymorphism is a concept which describes the process of performing a single
action in different ways. In Short, Polymorphism means “many forms”. In terms of programming
language, you can declare multiple methods with the same name until they have different
characteristics or parameters.

You might also like