Salesforce Menu

Encapsulation In Apex

Wrapping (or Binding) method and data together into a single unit is known as encapsulation. For example: medical capsule, it is bind with different medicines.

An Apex class is the example of encapsulation. Apex bean is the fully encapsulated class because all the data members are private here.

For example, this is an apex class :

public class MyWrapper
	private String name;
	public void addToName (String text)
		name = name + text;

This apex class combines two properties, name with a method called addToName as well. This is how an apex class combines logic to embody encapsulation in apex.

Subscribe Now