The Four Pillars of Object-Oriented Programming: A Comprehensive Guide
In my previous blog series, we explored how Python Pandas simplifies data manipulation and analysis. Now, let's shift our focus to Object-Oriented Programming (OOP), a powerful paradigm that helps organize code and manage complexity in software development. OOP is essential for building modular, reusable, and scalable applications. In this post, we'll start by diving into the Four Pillars of OOP, the key principles that every programmer should know.
Introduction to Object Oriented Programming (OOP)
Object Oriented Programming, simply known as OOP is a
programming paradigm that revolves the software design around the two
fundamental concepts: objects and classes. Java, Python, C++ are some of the
popular OO languages.
An object is something which represents something tangible
or intangible in the real world. For example, in a system, an object can
represent a BankAccount, Car, Employee, …
Objects have three main characteristics.
- Identity - Helps to identify an object uniquely.
Ex: BankAccount – accountNumber
Car – licensePlate
Employee – EPF_number
- State/ Attributes - Characteristics/ features of the object.
Ex: BankAccount – accountNumber, balance, …
Car – licensePlate, make, model, …
Employee – EPF_number, nic, name, address, …
- Behavior - What the object can do and how it responds to events
Ex: BankAccount – depositCash(), withdrawCash(), …
Car – start(), accelerate(), reverse(), …
Employee – raiseSalary(), changeManager(), …
A class is a grouping of objects with similar
characteristics. Basically, class is the blueprint of an object.
Hence, we can say that an object is an
instance of a class.
Let’s dive into the four key pillars of OOP.
Encapsulation refers to wrapping up of data under a single unit where the data of a particular class are hidden from any other class and can be accessed only via a member function of their class in which they are declared. This is also known as data hiding.
2. Abstraction
Abstraction
of data means only the essential information about the data should be given to
the outside world, and the background details or the implementation should be
hidden.
Ex: By considering the real-world scenario of a man driving a car, all he knows is that pressing the accelerators will increase the speed of the car, or applying breaks will stop the car, but he does not know the inner implementation mechanism of how the speed is increased upon pressing the accelerator.
Why OOP?
·
It ensures code reusability.
·
Enhances productivity.
·
Ensures code flexibility.
·
Changes can be made effortlessly.
·
Real-world problems can be easily solved with
OOP.
·
It does not require you to write the basic codes
repeatedly.
·
Consistency can be maintained throughout the
code.
·
Data hiding feature offers better security.
·
Lowers the development costs.
· Easy maintenance of codes.






Comments
Post a Comment