0% found this document useful (0 votes)
30 views5 pages

Topics: Abstraction Encapsulation

The document discusses abstraction and encapsulation in object-oriented programming. It defines abstraction as representing essential features of interest without background details to manage complexity. Encapsulation is wrapping code and data together in a class, controlling access through public, private and protected. Examples show using abstraction through functions and encapsulation by grouping data and methods in a class capsule.

Uploaded by

Shubhankar Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views5 pages

Topics: Abstraction Encapsulation

The document discusses abstraction and encapsulation in object-oriented programming. It defines abstraction as representing essential features of interest without background details to manage complexity. Encapsulation is wrapping code and data together in a class, controlling access through public, private and protected. Examples show using abstraction through functions and encapsulation by grouping data and methods in a class capsule.

Uploaded by

Shubhankar Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Topics

• Abstraction
• Encapsulation

1 Object-Oriented Programming
Abstraction
https://en.wikipedia.org/wiki/Abstraction_(software_engineering)

• Way of managing complexity by suppressing the complex


details
• Abstraction refers to the act of representing essential features
that are of interest of the users without including background
details or explanation.
• Users of a complex system are presented with a well defined
simple interface for its use
• Classes use the concept of abstraction for hiding unnecessary
implementation/algorithmic details of its methods.
• As user of any ‘class’ what you should be aware about that
class ?

2 Object-Oriented Programming
Abstraction: Simple Examples

• Suppose you have to compute the square root of a


‘double’ type number in a ‘C’ program. As a programmer
what You have to do.
o #include <math.h>
o Use sqrt() function
• What you will do if you have to compare two strings in a
‘C’ program
o #include <string.h>
o Use strcmp() function

3 Object-Oriented Programming
Encapsulation

• Encapsulation means wrapping/binding up of


data-part (state) and methods (operations , code)
together in the form of a capsule.
• Access to code (Methods) and data (instance
fields) is tightly controlled.
• Through Encapsulation, developer of a class can
decide what and what can not be accessible
outside a class. [ public , private , protected ]
• A class is a perfect example of an Encapsulation

4 Object-Oriented Programming
Encapsulation : Examples

Encapsulation keeps Data Part + Methods Methods

Operation Part of an object Data


together inside a capsule Methods Methods

class BOX
{
private double length;
private double width;
private double height; Class Capsule

public double area() { }


public double volume() { }
} // End of class BOX

5 Object-Oriented Programming

You might also like