Загрузил(а) файлы в ''
This commit is contained in:
parent
f43e9fcbe5
commit
605e39e09e
|
@ -2,15 +2,15 @@ abstract class Drinkable {
|
|||
void pour();
|
||||
}
|
||||
|
||||
class Beer implements Drinkable {
|
||||
class Lemonade implements Drinkable {
|
||||
void pour() {
|
||||
print("Pouring a delicious beer!");
|
||||
print("Пью холодный лемонад!");
|
||||
}
|
||||
}
|
||||
|
||||
class Coffee implements Drinkable {
|
||||
void pour() {
|
||||
print("Pouring a refreshing coffee!");
|
||||
print("Пью горячий шоклад!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,9 @@ abstract class DrinkFactory {
|
|||
DrinkFactory();
|
||||
}
|
||||
|
||||
class Pub implements DrinkFactory {
|
||||
class Cafe implements DrinkFactory {
|
||||
Drinkable createDrink() {
|
||||
return Beer();
|
||||
return Lemonade();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,24 +32,24 @@ class CoffeeShop implements DrinkFactory {
|
|||
}
|
||||
|
||||
void main() {
|
||||
var mood = "sleepy";
|
||||
var temperature = "cold";
|
||||
late DrinkFactory destination;
|
||||
|
||||
switch (mood) {
|
||||
case "sleepy":
|
||||
switch (temperature) {
|
||||
case "cold":
|
||||
destination = CoffeeShop();
|
||||
break;
|
||||
case "done":
|
||||
destination = Pub();
|
||||
case "warm":
|
||||
destination = Cafe();
|
||||
break;
|
||||
default:
|
||||
print("I only have two moods...");
|
||||
print("Мне ни холодно, ни жарко...");
|
||||
}
|
||||
|
||||
var myBeverage = destination.createDrink();
|
||||
myBeverage.pour();
|
||||
var drinkable = destination.createDrink();
|
||||
drinkable.pour();
|
||||
|
||||
/*
|
||||
Pouring a refreshing coffee!
|
||||
Пью горячий шоклад!
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue