Encapsulation promotes maintenance and code reusability by controlling access to data and code. It is implemented by defining public interfaces and keeping data and non-essential operations private. Object-oriented programming provides advantages like clear modular structure, easy maintenance and modification of existing code, and reusable code libraries. Key concepts of OOP include objects, classes, abstraction, encapsulation, inheritance, and polymorphism. Abstraction focuses on essential features while hiding background details, and encapsulation stores data and accessing functions together within a class.
1 of 4
Downloaded 16 times
More Related Content
Benefits of encapsulation
1. Benefits of Encapsulation
In summary the benefits of encapsulation are:
Encapsulation promotes maintenance
Code changes can be made independently
Increases usability
And encapsulation is implemented with:
Public interfaces
controls of visibility of operations & state
data is private / not accessible
Advantages of OOP
Object-Oriented Programming has the following advantages over conventional approaches:
OOP provides a clear modular structure for programs which makes it good for defining
abstract datatypes where implementation details are hidden and the unit has a clearly
defined interface.
OOP makes it easy to maintain and modify existing code as new objects can be created
with small differences to existing ones.
OOP provides a good framework for code libraries where supplied software components
can be easily adapted and modified by the programmer. This is particularly useful for
developing graphical user interfaces.
Concepts of OOP:
Objects
Classes
Data Abstraction and Encapsulation
Inheritance
Polymorphism
Objects
Objects are the basic run-time entities in an object-oriented system. Programming problem is
analyzed in terms of objects and nature of communication between them. When a program is
2. executed, objects interact with each other by sending messages. Different objects can also
interact with each other without knowing the details of their data or code.
Classes
A class is a collection of objects of similar type. Once a class is defined, any number of objects
can be created which belong to that class.
Data Abstraction and Encapsulation
Abstraction refers to the act of representing essential features without including the background
details or explanations. Classes use the concept of abstraction and are defined as a list of
abstract attributes. Storing data and functions in a single unit (class) is encapsulation. Data
cannot be accessible to the outside world and only those functions which are stored in the class
can access it.
Inheritance
Inheritance is the process by which objects can acquire the properties of objects of other class.
In OOP, inheritance provides reusability, like, adding additional features to an existing class
without modifying it. This is achieved by deriving a new class from the existing one. The new
class will have combined features of both the classes.
Polymorphism
Polymorphism means the ability to take more than one form. An operation may exhibit different
behaviors in different instances. The behavior depends on the data types used in the operation.
Polymorphism is extensively used in implementing Inheritance.
http://www.saviost.net/object-oriented-programming-oop-encapsulation-inheritance-
polymorphism-abstraction/
http://freshersjunction.blogspot.com/2015/03/what-is-encapsulation-real-time-example.html
3. Difference between Abstraction and
Encapsulation :-
Abstraction Encapsulation
1. Abstraction solves the problem in
the design level.
1. Encapsulation solves the problem
in the implementation level.
2. Abstraction is used for hiding the
unwanted data and giving relevant
data.
2. Encapsulation means hiding the
code and data into a single unit to
protect the data from outside world.
3. Abstraction lets you focus on
what the object does instead of how
it does it
3. Encapsulation means hiding the
internal details or mechanics of how
an object does something.
4. Abstraction- Outer layout, used
in terms of design.
For Example:-
Outer Look of a Mobile Phone, like
it has a display screen and keypad
buttons to dial a number.
4. Encapsulation- Inner layout,
used in terms of implementation.
For Example:- Inner
Implementation detail of a Mobile
Phone, how keypad button and
Display Screen are connect with
each other using circuits.
The easier way to understand Abstraction and encapsulation is as
follows:-
Real World Example:-
Take an example of Mobile Phone:-
4. You have a Mobile Phone, you can dial a number using keypad buttons. Even
you don't know how these are working internally. This is called Abstraction.
You have the only information that is needed to dial a number. But not its
internal working of mobile.
But how the Mobile Phone internally working?, how keypad buttons are
connected with internal circuit? is called Encapsulation.
Summary:
"Encapsulation is accomplished by using Class. - Keeping data and methods
that accesses that data into a single unit"
"Abstraction is accomplished by using Interface. - Just giving the abstract
information about what it can do without specifying the back ground details"
"Information/Data hiding is accomplished by using Modifiers - By keeping
the instance variables private or protected."