-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 976c8e5
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |