An open API service indexing awesome lists of open source software.

https://github.com/sassman/edu-decorator-pattern-php

Illustrating the usage and the use case of the decorator pattern.
https://github.com/sassman/edu-decorator-pattern-php

decorator-pattern design-patterns php

Last synced: about 1 year ago
JSON representation

Illustrating the usage and the use case of the decorator pattern.

Awesome Lists containing this project

README

          

decorator-pattern-php
=====================

Illustrating the usage and the use case of the decorator pattern.
This is only educational material. No production grade code.

The Problem is code like this:
```php
addProduct(new Hamburger());
$bill->addProduct(new CheeseburgerWithOnion());
$bill->addProduct(new CheeseburgerWithDoubleCheese());

printf("==============================\n");
printf("Total is %2.2f\n", $bill->getTotal());
```

The solution is evolving to

```php
addProduct(new Hamburger());
$bill->addProduct(new Cheeseburger(new Onion()));
$bill->addProduct(new Cheeseburger(new Cheese()));

printf("==============================\n");
printf("Total is %2.2f\n", $bill->getTotal());
```

to improve the design, flexibility but most importantly the maintainability.