Salesforce Menu

Apex OOPs Concepts

Object means a real world / run time entity such as marker, car, table, chair etc. Object-Oriented Programming is a methodology or way to design a program using classes and objects. It eases the software development and its maintenance by providing some beautiful concepts as followed.

  • Classes
  • Objects
  • Encapsulation
  • Polymorphism
  • Inheritance
  • Abstraction

Object

Any real world entity that has state and behavior is known as an object. For example: marker, book, table, chair, mouse, car etc.

Technically, we can say object is an instance of a class or in other words you can say it is an implementation of a class.

Class

Class is a concept or prototype or template i.e. it is a logical entity.

Technically, we can say that we create an individual object of a class.

Encapsulation

It is a binding of code and data together into a single unit known as encapsulation. For example, a capsule, it is wrapped with different types medicines into single unit.

An apex class is the example of encapsulation.

Polymorphism

One name many forms known as polymorphism. Real world example of polymorphism: A person at the same time can have different characteristic. Like a woman at the same time is a mother, a wife, an employee and a daughter etc.

In Apex, we use method overloading and method overriding to achieve polymorphism.

Inheritance

When one class acquires all the properties and behaviors of super/parent class it is known as inheritance. It provides code reusability as well as we can used to achieve runtime polymorphism.

Note: Without inheritance we cannot achieve runtime polymorphism.

Abstraction

Hiding internal complexity and showing functionality is known as abstraction. For example: Car Drive, we don’t know the internal processing.

In Apex, we use abstract class and interface to achieve abstraction.

Subscribe Now