Abstraction in c++ and Real Life Example of Abstraction in C++

HiteshKumar71 1,272 views 6 slides Sep 09, 2019
Slide 1
Slide 1 of 6
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6

About This Presentation

Abstraction in c++ and Real Life Example of Abstraction in C++ - Abstraction is one of the features of Object-Oriented Programming, where you show only relevant details to the user and hide irrelevant details.


Slide Content

Sitesbay.com


Abstraction in C++
Real Life Example of Abstraction in C++
Hitesh Kumar
SITESBAY.COM

Sitesbay.com




Abstraction in C++
Real Life Example of Abstraction in C++

Sitesbay.com
Abstraction in C++
Abstraction in C++ is not new concept it is oop’s concept which is used to hide background detail and
show only essential features.
Data abstraction is a process of representing the essential features without including implementation
details.


Data abstraction is the process of representing essential details not including internal details. Example
index of the book

Data abstraction refers to, providing only essential features by hiding its background details.
Example of Abstraction in C++:

class result
{
int marks;
float percentage;
char name[20];

Sitesbay.com
void input();
void output();
}

main()
{
bank b1;
b1.input();
b1.output();
}

In the above example, b1 is an object calling input and output member functions, but that code is
invisible to the object b1.
Abstract Class

Abstract Class is a class which contains at least one Pure Virtual function in it.

Characteristics of Abstract Class

 Abstract class cannot be instantiated, but pointers and references of Abstract class type can be
created.
 Abstract class can have normal functions and variables along with a pure virtual function.
 Abstract classes are mainly used for Up-casting, so that its derived classes can use its interface.
 Classes inheriting an Abstract Class must implement all pure virtual functions, or else they will
become Abstract too.

Sitesbay.com
1. Real Life Example of Abstraction in C++
Suppose you are operating a mobile phone. You know that the important feature of a
phone is the memory card, SIM, battery life, design and build, and processor power. But,
while operating the phone you do not get into the operational details of the phone such
as how the CPU of the phone allocates memory for the various media on your phone or
other intricate architectural details of the phone. All these details aren’t visible to cell-
phone users from a non-technical background.

2. Real Life Example of Abstraction in C++
A man driving a car. The man only knows that pressing the accelerators will
increase the speed of car or applying brakes will stop the car but he does not
know about how on pressing accelerator the speed is actually increasing, he does
not know about the inner mechanism of the car or the implementation of
accelerator, brakes etc in the car.
Advantages of Data Abstraction in C++
How we discuss about some advantages of data abstraction;
1. Data abstraction increases the reusability of the code by avoiding any chances of
redundancy.
2. It increases the readability of the code as it eliminates the possibility of displaying the
complex working of the code.
3. With the implementation of classes and objects, comes enhanced security. Since data
abstraction is a method of implementing classes and objects any denying access to other
classes of accessing the data members and member functions of the base class.

Sitesbay.com
4. It helps the user to write a high-level code.
5. It separates the entire program into code and implementation making it more
comprehensible.

Designing Strategy of Abstraction
Abstraction separates code into interface and implementation. So while designing your
component, you must keep interface independent of the implementation so that if you
change underlying implementation then interface would remain intact.

In this case whatever programs are using these interfaces, they would not be impacted
and would just need a recompilation with the latest implementation.