OOP Concepts
OOP Concepts
Multiple objects of the same class uses same code and thus promotes code
reusability.
While procedural programming focuses on functions and lacks data hiding, OOP
emphasizes objects, encapsulation, and better organization of code. OOP is particularly
useful for managing large projects and modeling real-world scenarios.
OOP CONCEPTS
Class
Object
Encapsulation
Inheritance
Polymorphism
Abstraction
C L A SS
A class is a blueprint or template for creating objects. It defines the structure (attributes) and
behavior (methods) that objects of that class will have. Think of a class as a cookie cutter, and objects
as the cookies you cut out using that shape.
Attributes (Properties): These are like the characteristics or properties of an object. For a
house, attributes could be things like the number of rooms, color, and size.
Methods (Functions): These are like the actions the object can perform. For a house,
methods could include opening doors, turning on lights, or playing music.
So, a class bundles together both data (attributes) and actions (methods).
OBJECT
Object is an instance of a class. In OOP, an object is like one of those real-world
items. It’s a self-contained unit that combines both data (attributes) and behavior
(actions).
Objects are created based on classes. A class is like a blueprint that defines what an
object should look like and what it can do.
OOP promotes reusability. Once you define a class, you can create as many objects
as needed.
Classes provide the rules for creating these objects, ensuring consistency and
organization in your code.
E N C A P S U L AT I O N
Encapsulation involves bundling data (attributes or fields) and the methods
(functions) that operate on that data within a single unit, known as a class.
Encapsulation allows you to hide the internal state of an object from the outside world.
Encapsulation enhances security by hiding sensitive data and exposing only essential
interfaces for interaction. This prevents external code from directly manipulating
internal state, reducing the risk of unauthorized access or unintended side effects.
I N H E R I TA N C E
Inheritance is a fundamental concept in Object-Oriented Programming (OOP)
that allows a new class (subclass) to inherit properties and behavior (methods) from an
existing class (superclass). This enables code reuse and promotes the concept of
hierarchy in software design.
The class that is being inherited from is called the superclass or base class.
The class that inherits from the superclass is called the subclass or derived class.