56 lines
965 B
Dart
56 lines
965 B
Dart
abstract class Drinkable {
|
|
void pour();
|
|
}
|
|
|
|
class Lemonade implements Drinkable {
|
|
void pour() {
|
|
print("Пью холодный лемонад!");
|
|
}
|
|
}
|
|
|
|
class Coffee implements Drinkable {
|
|
void pour() {
|
|
print("Пью горячий шоклад!");
|
|
}
|
|
}
|
|
|
|
abstract class DrinkFactory {
|
|
Drinkable createDrink();
|
|
DrinkFactory();
|
|
}
|
|
|
|
class Cafe implements DrinkFactory {
|
|
Drinkable createDrink() {
|
|
return Lemonade();
|
|
}
|
|
}
|
|
|
|
class CoffeeShop implements DrinkFactory {
|
|
Drinkable createDrink() {
|
|
return Coffee();
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
var temperature = "cold";
|
|
late DrinkFactory destination;
|
|
|
|
switch (temperature) {
|
|
case "cold":
|
|
destination = CoffeeShop();
|
|
break;
|
|
case "warm":
|
|
destination = Cafe();
|
|
break;
|
|
default:
|
|
print("Мне ни холодно, ни жарко...");
|
|
}
|
|
|
|
var drinkable = destination.createDrink();
|
|
drinkable.pour();
|
|
|
|
/*
|
|
Пью горячий шоклад!
|
|
*/
|
|
}
|