Object Oriented Programming (OOP) is a programming paradigm based on the concept of “objects”, which can contain data, in the form of variables (fields, attributes or properties), and code, in the form of methods.
Some of the object-oriented programming languages are Java, C++, C#, Python, PHP, Dart, Swift, Scala, Kotlin etc.,
Let us know some basics about Class and Object.
- A class is a user defined Blueprint from which objects are created.
- Class has a collection of methods and variables.
- Class is a logical entity and it is a group of similar objects.
- Class doesn’t allocate memory when it is created.
- Classes have variables, methods, constructors, access modifiers (private, public, protected, internal), keywords, interfaces etc.,
- An Object is an instance of a class.
- Memory is allocated when the objects are created
- Objects have State (variables), Behaviour (methods) and Identity
- For example, dogs have state (name, color, hungry) and dogs have behavior (barking, fetching).
Let’s see some real life examples of class and object
Object: Apple, Banana, Mango, Guava
Object: Car, Bus, Truck
Object Oriented Programming Concepts
Abstraction (Show what is necessary)
- Abstraction is process of hiding the implementation details and showing only the functionality.
- With Abstraction, other classes will have the information on what the object does instead of how it does it.
- Abstraction is achieved using Abstract Classes and Interfaces.
Encapsulation (Hide Complexity)
- Wrapping of Data (variables) and Code (methods) into a Single Unit is known as Encapsulation.
- Encapsulation can be achieved using Class Concept
- Variables of a class are hidden from other classes by declaring as Private and it can be accessed only through the methods of their current class. That is, by defining public setter and getter methods to modify and view the variables values.
- It is the process in which one class (Child Class/Sub Class/Derived Class) is allowed to inherit the features (variables and methods) of another class (Parent Class/Super Class).
- Inheritance supports Code Reusability
- It is the ability of an object to take on many forms based on the context.
- Polymorphism can be achieved with Overloading and Overriding
- Overloading (Compile Time or Static Polymorphism)
- It allows different methods to have the same name with different signatures where the signature can be different by the number of input parameters or type of input parameters or both
- Overriding (Run Time Polymorphism)
- It is the concept of having two methods with the same method name and parameters
- Overloading vs Overriding
- Overloading happens at Compile Time while Overriding happens at runtime.
- Static binding is being used for overloaded methods and dynamic binding is being used for overriding methods.
Learn more about Implementation of Object Oriented Programming concepts using Python, Java, C# etc., in the next upcoming Blog Articles.