Skip to content

Commit 6a188f2

Browse files
committed
chore: translates decorator pattern
1 parent 727661f commit 6a188f2

File tree

7 files changed

+37
-37
lines changed

7 files changed

+37
-37
lines changed

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ tutti i suoi dipendenti vengono notificati e aggiornati automaticamente.
2626
php src/Observer/weather-station.php
2727
```
2828
### Decorator pattern
29-
Il pattern Decorator associa responsabilità aggiuntive a un oggetto in modo dinamico. I decoratori offrono un'alternativa
30-
flessibile alla sottoclasse per estendere le funzionalità di un oggetto.
29+
Decorator pattern associates additional responsibilities with an object in a dynamic way. Decorators offer an alternative
30+
flexible to the subclass to extend the functionality of an object.
3131
```
3232
php src/Decorator/starbuzz-coffee.php
3333
```

src/Decorator/Beverage/Beverage.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
abstract class Beverage
88
{
9-
public const PICCOLO = 0;
10-
public const MEDIO = 1;
11-
public const GRANDE = 2;
9+
public const SMALL = 0;
10+
public const MEDIUM = 1;
11+
public const BIG = 2;
1212

13-
protected string $description = 'Bevanda non definita';
13+
protected string $description = 'Undefined beverage';
1414

15-
protected int $size = self::PICCOLO;
15+
protected int $size = self::SMALL;
1616

1717
public function getDescription(): string
1818
{

src/Decorator/Condiment/CondimentDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
abstract class CondimentDecorator extends Beverage
1010
{
1111
protected Beverage $beverage;
12-
protected string $condimentDescription = 'Condimento sconosciuto';
12+
protected string $condimentDescription = 'Unknown condiment';
1313

1414
public function __construct(Beverage $beverage)
1515
{

src/Decorator/Condiment/ConCacao.php renamed to src/Decorator/Condiment/Macchiato.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
use DesignPatterns\Decorator\Beverage\Beverage;
88

9-
class ConCacao extends CondimentDecorator
9+
class Macchiato extends CondimentDecorator
1010
{
1111
public function cost(): float
1212
{
1313
$cost = $this->beverage->cost();
1414

1515
switch ($this->beverage->size) {
16-
case Beverage::PICCOLO:
16+
case Beverage::SMALL:
1717
$cost += 0;
1818

1919
break;
20-
case Beverage::MEDIO:
20+
case Beverage::MEDIUM:
2121
$cost += 0.15;
2222

2323
break;
24-
case Beverage::GRANDE:
24+
case Beverage::BIG:
2525
$cost += 0.20;
2626

2727
break;
@@ -32,6 +32,6 @@ public function cost(): float
3232

3333
protected function setDescription(): void
3434
{
35-
$this->condimentDescription = 'con cacao';
35+
$this->condimentDescription = 'macchiato';
3636
}
3737
}

src/Decorator/Condiment/SoyMilk.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public function cost(): float
1313
$cost = $this->beverage->cost();
1414

1515
switch ($this->beverage->size) {
16-
case Beverage::PICCOLO:
16+
case Beverage::SMALL:
1717
$cost += 0.25;
1818

1919
break;
20-
case Beverage::MEDIO:
20+
case Beverage::MEDIUM:
2121
$cost += 0.5;
2222

2323
break;
24-
case Beverage::GRANDE:
24+
case Beverage::BIG:
2525
$cost += 0.75;
2626

2727
break;
@@ -32,6 +32,6 @@ public function cost(): float
3232

3333
protected function setDescription(): void
3434
{
35-
$this->condimentDescription = 'con latte di soia';
35+
$this->condimentDescription = 'with soy milk';
3636
}
3737
}

src/Decorator/Condiment/Schiumato.php renamed to src/Decorator/Condiment/WithCocoa.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
use DesignPatterns\Decorator\Beverage\Beverage;
88

9-
class Schiumato extends CondimentDecorator
9+
class WithCocoa extends CondimentDecorator
1010
{
1111
public function cost(): float
1212
{
1313
$cost = $this->beverage->cost();
1414

1515
switch ($this->beverage->size) {
16-
case Beverage::PICCOLO:
16+
case Beverage::SMALL:
1717
$cost += 0;
1818

1919
break;
20-
case Beverage::MEDIO:
20+
case Beverage::MEDIUM:
2121
$cost += 0.15;
2222

2323
break;
24-
case Beverage::GRANDE:
24+
case Beverage::BIG:
2525
$cost += 0.20;
2626

2727
break;
@@ -32,6 +32,6 @@ public function cost(): float
3232

3333
protected function setDescription(): void
3434
{
35-
$this->condimentDescription = 'schiumato';
35+
$this->condimentDescription = 'with cocoa';
3636
}
3737
}

src/Decorator/starbuzz-coffee.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,45 @@
77
use DesignPatterns\Decorator\Beverage\Beverage;
88
use DesignPatterns\Decorator\Beverage\Cappuccino;
99
use DesignPatterns\Decorator\Beverage\Espresso;
10-
use DesignPatterns\Decorator\Condiment\ConCacao;
11-
use DesignPatterns\Decorator\Condiment\Schiumato;
10+
use DesignPatterns\Decorator\Condiment\WithCocoa;
11+
use DesignPatterns\Decorator\Condiment\Macchiato;
1212
use DesignPatterns\Decorator\Condiment\SoyMilk;
1313

1414
$cappuccino = new Cappuccino();
15-
$cappuccino->setSize(Beverage::GRANDE);
16-
$cappuccino = new ConCacao($cappuccino);
15+
$cappuccino->setSize(Beverage::BIG);
16+
$cappuccino = new WithCocoa($cappuccino);
1717
printBeverage($cappuccino);
1818

1919
$cappuccino2 = new Cappuccino();
20-
$cappuccino2->setSize(Beverage::PICCOLO);
20+
$cappuccino2->setSize(Beverage::SMALL);
2121
$cappuccino2 = new SoyMilk($cappuccino2);
2222
printBeverage($cappuccino2);
2323

2424
$espresso = new Espresso();
25-
$espresso->setSize(Beverage::MEDIO);
26-
$espresso = new Schiumato($espresso);
27-
$espresso = new ConCacao($espresso);
25+
$espresso->setSize(Beverage::MEDIUM);
26+
$espresso = new Macchiato($espresso);
27+
$espresso = new WithCocoa($espresso);
2828
printBeverage($espresso);
2929

3030
$espresso = new Espresso();
31-
$espresso->setSize(Beverage::PICCOLO);
31+
$espresso->setSize(Beverage::SMALL);
3232
printBeverage($espresso);
3333

3434
function printBeverage(Beverage $beverage): void
3535
{
3636
$size = '';
3737

3838
switch ($beverage->getSize()) {
39-
case Beverage::PICCOLO:
40-
$size = 'Piccolo';
39+
case Beverage::SMALL:
40+
$size = 'Small';
4141

4242
break;
43-
case Beverage::MEDIO:
44-
$size = 'Medio';
43+
case Beverage::MEDIUM:
44+
$size = 'Medium';
4545

4646
break;
47-
case Beverage::GRANDE:
48-
$size = 'Grande';
47+
case Beverage::BIG:
48+
$size = 'Big';
4949

5050
break;
5151
}

0 commit comments

Comments
 (0)