This commit is contained in:
Морозов Андрей 2022-03-29 11:11:19 +04:00
parent 7959da3cd7
commit 97c5cac80f
1 changed files with 15 additions and 23 deletions

View File

@ -8,25 +8,19 @@ class PizzaBuilder {
PizzaBuilder(this._diameter);
String get crust => _crust;
set crust(String newCrust) {
_crust = newCrust;
}
set crust(String newCrust) => _crust = newCrust;
int get diameter => _diameter;
set diameter(int newDiameter) {
_diameter = newDiameter;
}
set diameter(int newDiameter) => _diameter = newDiameter;
Set<String> get toppings => _toppings;
set toppings(Set<String> newToppings) {
_toppings = newToppings;
_ensureCheese();
}
void _ensureCheese() {
_toppings.add("cheese");
_addCheese();
}
void _addCheese() => _toppings.add("сыр");
Pizza build() {
return Pizza(this);
}
@ -49,32 +43,30 @@ class Pizza {
String _stringifiedToppings() {
var stringToppings = _toppings.join(", ");
var lastComma = stringToppings.lastIndexOf(",");
var replacement = ",".allMatches(stringToppings).length > 1 ? ", and" : " and";
var replacement = ",".allMatches(stringToppings).length > 1 ? ", и" : " и";
return stringToppings.replaceRange(lastComma, lastComma + 1, replacement);
}
@override
String toString() {
return "A delicous $_diameter\" pizza with $_crust crust covered in $toppings";
return "Пицца с $_diameter\" диметром с $_crust корочкой. Ингридиенты: $toppings";
}
}
void main() {
var pizzaBuilder = PizzaBuilder(8);
pizzaBuilder.crust = "deep dish";
pizzaBuilder.toppings = Set.from(["pepperoni"]);
pizzaBuilder.crust = "хрустящей";
pizzaBuilder.toppings = Set.from(["пеперони"]);
var plainPizza = Pizza(pizzaBuilder);
print("Behold! $plainPizza.");
assert(plainPizza.toString() == "Behold! A delicous 8\" pizza with deep dish crust covered in pepperoni and cheese.");
print("Заказана $plainPizza.");
pizzaBuilder.crust = "gold plated";
pizzaBuilder.diameter = 72;
pizzaBuilder.toppings = Set.from(["anchovies", "caviar", "diamonds"]);
pizzaBuilder.crust = "сырной";
pizzaBuilder.diameter = 10;
pizzaBuilder.toppings = Set.from(["ананасы"]);
var luxuriousPizza = pizzaBuilder.build();
print("Wow! $luxuriousPizza? Someone is rich!");
assert(luxuriousPizza.toString() == "Wow! A delicous 72\" pizza with gold plated crust covered in anchovies, caviar, diamonds, and cheese? Someone is rich!");
var ananasPizza = pizzaBuilder.build();
print("Заказана $ananasPizza!");
}