-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstraction.cpp
58 lines (39 loc) · 1.35 KB
/
Abstraction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
//abstraction means showing the important info and not showing the details
//hide complex details behind simple procedures
//abstract class is a class that has at least on pure virtual function
class smartphone{
public:
virtual void takeAselfie() = 0; //this is a pure virtual function, beacsue it will force each dervived class to implement this function in its own way
//this is abstraction, it shows the simple functionalities, without showing all the logic behind it, whoever wants to make a smartphone, needs to implement the functions aka derived classes will need to impklement
virtual void makeCall() = 0;
};
class Andriod:public smartphone{
public:
void takeAselfie(){
cout << "Andriod took a selfie\n";
}
void makeCall(){
cout << "Andriod makes a call\n";
}
};
class iphone:public smartphone{
public:
void takeAselfie(){
cout << "iphone took a selfie\n";
}
void makeCall(){
cout << "iphone makes a call\n";
}
};
int main(){
smartphone * s1 = new Andriod(); //you can make a base class pointer, point to a derived class object
s1->takeAselfie(); //use the -> to acess memebrs of a class when using pointers
smartphone * i1 = new iphone();
i1->takeAselfie();
s1->makeCall();
i1->makeCall();
Andriod phone;
phone.takeAselfie();
}