Before going to do coding in apex once recall the basics of object oriented programming(OOP) language concepts.
What is OOPs:
OOP (Objecte Oriented Programming) is a methodology, that provides a way of modularizing a program by creating partitioned memory area for both data and methods that can be used as template for creating a copies of such objects(Models) on demand.
Unlike procedural language, here in oops programming language programs are organised around objects and data rather than action and logic.
The main OOPs Principles used in apex Language are,
- Object
- Class
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
Object: In this real word Any entity that has state and behavior is known as an object. It can be physical and logical.
Example: Ball, Pen, Book, Clock, Apple etc.
Class: Class is a Collection of objects. It is a logical entity.
Example: Here tub is Class and ball is Object. Tub having many no of different color balls.
Inheritance: When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
Example: Parents producing the children inheriting qualities of the parents.
Polymorphism: When one task is performed by different ways simply it's called as polymorphism. we use method overloading and method overriding to achieve polymorphism.
Example: with one micro oven we can make different types of cakes.
Abstraction: Hiding internal details and showing functionality is known as abstraction.we use abstract class and interface to achieve abstraction.
Encapsulation: Binding (or wrapping) code and data together into a single unit is known as encapsulation.
Example: ATM machines, we don't know the inside ATM.