-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise.cpp
49 lines (43 loc) · 1.4 KB
/
Exercise.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
#include <iostream>
class OldCoffeeMachine {
public:
void selectA(){
std::cout<<"Coffee flavor A from old machine"<<"\n";
}
void selectB(){
std::cout<<"Coffee flavor B from old machine"<<"\n";
}
};
class CoffeeMachineInterface {
public:
void chooseFirstSelection(){
std::cout<<"Coffee flavor A from new machine"<<"\n";
}
void chooseSecondSelection(){
std::cout<<"Coffee flavor B from new machine"<<"\n";
}
};
class CoffeeTouchscreenAdapter : public CoffeeMachineInterface {
private:
OldCoffeeMachine* oldVendingMachine;
public:
CoffeeTouchscreenAdapter(OldCoffeeMachine* oldMachine){
oldVendingMachine = oldMachine;
}
void chooseFirstSelection(){
oldVendingMachine->selectA();
}
void chooseSecondSelection(){
oldVendingMachine->selectB();
}
};
int main(){
OldCoffeeMachine* oldVendingMachine = new OldCoffeeMachine;
CoffeeMachineInterface* newMachine = new CoffeeMachineInterface;
CoffeeTouchscreenAdapter* oldMachine = new CoffeeTouchscreenAdapter(oldVendingMachine);
newMachine->chooseFirstSelection();
newMachine->chooseSecondSelection();
oldMachine->chooseFirstSelection();
oldMachine->chooseSecondSelection();
return 0;
}