Object Oriented
Programming I
, Encapsulation and
Information Hiding
, Introduction
Encapsulation and Information Hiding are two
fundamental, closely related concepts in Object-
Oriented Programming (OOP).
Together, they form a crucial pillar of creating
robust, secure, and maintainable software.
At its core, encapsulation is about bundling data
(attributes) and the methods (functions) that
operate on that data into a single unit, known as a
class.
Think of it like a capsule that holds medicine;
the capsule protects the medicine and keeps it
together.
3
SPC2204: Object Oriented Programming 1
, Introduction
Similarly, encapsulation in programming holds
data and its functions together, protecting the
data from external, unauthorized access.
This bundling gives rise to information hiding,
which is the practice of restricting access to
certain parts of an object's internal state.
This prevents the internal implementation
details of a class from being exposed to the
outside world, thereby ensuring data integrity
and allowing for modifications to the internal
logic without affecting the external code that
uses the class.
4
SPC2204: Object Oriented Programming 1
Programming I
, Encapsulation and
Information Hiding
, Introduction
Encapsulation and Information Hiding are two
fundamental, closely related concepts in Object-
Oriented Programming (OOP).
Together, they form a crucial pillar of creating
robust, secure, and maintainable software.
At its core, encapsulation is about bundling data
(attributes) and the methods (functions) that
operate on that data into a single unit, known as a
class.
Think of it like a capsule that holds medicine;
the capsule protects the medicine and keeps it
together.
3
SPC2204: Object Oriented Programming 1
, Introduction
Similarly, encapsulation in programming holds
data and its functions together, protecting the
data from external, unauthorized access.
This bundling gives rise to information hiding,
which is the practice of restricting access to
certain parts of an object's internal state.
This prevents the internal implementation
details of a class from being exposed to the
outside world, thereby ensuring data integrity
and allowing for modifications to the internal
logic without affecting the external code that
uses the class.
4
SPC2204: Object Oriented Programming 1