Blocks of OOP
- Classes are essentially user-defined data types.
- Objects are instances of a class.
- Methods represent behaviors. Methods perform actions; methods might return information about an object or update an object’s data. The method’s code is defined in the class definition.
- Attributes are the information that is stored. Attributes are defined in the Class template.
Four Principles of OOP
The four pillars of object-oriented programming are:
- Inheritance: child classes inherit data and behaviors from the parent class
- Encapsulation: containing information in an object, exposing only selected information
- Abstraction: only exposing high-level public methods for accessing an object
- Polymorphism: many methods can do the same task
Encapsulation requires defining some fields as private and some as public.
Private/ Internal interface: methods and properties accessible from other methods of the same class.
Public / External Interface: methods and properties accessible from outside the class.
Method Overriding
Runtime polymorphism uses method overriding. In method overriding, a child class can implement differently than its parent class.
Method Overloading
Compile Time polymorphism uses method overloading. Methods or functions may have the same name but a different number of parameters passed into the method call. Different results may occur depending on the number of parameters passed in.
Languages with OOP
- Java
- JavaScript
- Python
- C++
- C#
Resources: educative https://www.educative.io/blog/object-oriented-programming