Chapter 1 - Unit I _ Introduction to OOP Concepts
Chapter 1 - Unit I _ Introduction to OOP Concepts
In POP, data and procedures are treated as separate entities, and data is often passed between
procedures as parameters. The focus is on breaking down a problem into smaller, more manageable
procedures or functions that can be called as needed, rather than on creating objects that encapsulate
data and behavior.
In OOP, data and behavior are treated as a single unit called an object. An object has properties (also
known as attributes or fields) that represent its state and methods (also known as functions or
procedures) that represent its behavior. Methods operate on the object's properties, and they can also
interact with other objects.
Few examples of Object Oriented Programming are Java, C++, C# and Python.
Encapsulation is one of the fundamental concepts of object-oriented programming (OOP) that binds
together, code and the data it manipulates, into a single unit called class, and keeps both safe from
outside interference and misuse. Access to the code and data inside the class is tightly controlled
through a well-defined public interface. Encapsulation provides a number of benefits, such as improved
security and data integrity, easier maintenance and debugging of code.
What is Inheritance?
Inheritance is one of the fundamental concepts of object-oriented programming (OOP) that enables a
new class to be based on an existing class, and inherit the properties and methods of that class. The
existing class is known as the superclass, base class, or parent class, while the new class is known as
the subclass, derived class, or child class.
Polymorphism means the ability of an object to behave differently in different circumstances or we can
say it is the ability for a message or data to be processed in more than one form.
What is Abstraction?
Abstraction is a fundamental concept of object-oriented programming (OOP) that refers to the process
of defining and representing the essential features of a system, while hiding or abstracting away the
irrelevant or unnecessary details.
In object-oriented programming (OOP), data hiding refers to the concept of encapsulating data within a
class and restricting access to it from outside the class. This is achieved by declaring the class's
attributes (data members) as private or protected, which means they can only be accessed or modified
by methods (member functions) defined within the class itself.
Data hiding helps to ensure that the internal state of an object remains consistent and valid by
preventing external code from directly manipulating its data. Instead, external code interacts with the
object through a well-defined interface provided by public methods. This enhances the modularity and
maintainability of the codebase, as changes to the internal implementation of a class can be made
without affecting the code that uses the class.
The object-oriented programming (OOP) approach is preferred in complex programming due to its
ability to promote modularity, reusability, encapsulation, abstraction, polymorphism, and hierarchical
organization. By breaking down complex systems into smaller, manageable units called objects, OOP
facilitates modular design, allowing developers to focus on individual components without needing to
understand the entire system at once. Through inheritance and composition, OOP enables code reuse,
reducing duplication and promoting extensibility. Encapsulation hides internal details, simplifying code
maintenance and reducing dependencies. Abstraction provides simplified representations of real-world
entities, making code more understandable and maintainable. Polymorphism allows for generic code
that can handle a variety of objects interchangeably, while hierarchical organization helps to structure
complex systems in a clear and logical manner. Overall, the OOP approach provides a powerful
framework for managing complexity and improving software design in the context of complex
programming tasks.
Data hiding and encapsulation are both fundamental principles in object-oriented programming (OOP),
but they differ in scope and emphasis. Data hiding specifically pertains to the practice of restricting
access to certain data members within a class, typically by declaring them as private or protected,
aiming to prevent external code from directly manipulating the internal state of an object. On the other
hand, encapsulation encompasses the broader concept of bundling data and methods together within a
class to create a cohesive and modular unit. While data hiding focuses on controlling access to data,
encapsulation emphasizes the encapsulation of data and behavior within a single entity, promoting
modularity, abstraction, and information hiding. Therefore, while data hiding is a key aspect of
encapsulation, encapsulation extends beyond data hiding to include the overall organization and
structuring of classes to enhance code maintainability and flexibility.