@@ -313,16 +313,37 @@ As you can see; the number of constructor parameters can quickly get out of hand
313313
314314** Programmatic Example**
315315
316- The sane alternative is to use the builder pattern.
316+ The sane alternative is to use the builder pattern. First of all we have our burger that we want to make
317317
318318``` php
319- class BurgerBuilder {
319+ class Burger {
320320 protected $size;
321321
322- protected $cheeze = true ;
322+ protected $cheeze = false ;
323323 protected $pepperoni = false;
324324 protected $lettuce = false;
325325 protected $tomato = false;
326+
327+ public function __construct(BurgerBuilder $builder) {
328+ $this->size = $builder->size;
329+ $this->cheeze = $builder;
330+ $this->pepperoni = $builder->pepperoni;
331+ $this->lettuce = $builder->lettuce;
332+ $this->tomato = $builder->tomato;
333+ }
334+ }
335+ ```
336+
337+ And then we have the builder
338+
339+ ``` php
340+ class BurgerBuilder {
341+ public $size;
342+
343+ public $cheeze = false;
344+ public $pepperoni = false;
345+ public $lettuce = false;
346+ public $tomato = false;
326347
327348 public function __construct(int $size) {
328349 $this->size = $size;
@@ -338,14 +359,18 @@ class BurgerBuilder {
338359 return $this;
339360 }
340361
362+ public function addCheeze() {
363+ $this->cheeze = true;
364+ return $this;
365+ }
366+
341367 public function addTomato() {
342368 $this->tomato = true;
343369 return $this;
344370 }
345371
346372 public function build() : Burger {
347- // creational logic
348- return $burger;
373+ return new Burger($this);
349374 }
350375}
351376```
0 commit comments