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.
- Host: GitHub
- URL: https://github.com/sassman/edu-decorator-pattern-php
- Owner: sassman
- License: mit
- Created: 2017-10-23T10:21:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-23T10:30:21.000Z (over 8 years ago)
- Last Synced: 2025-01-31T15:36:38.289Z (over 1 year ago)
- Topics: decorator-pattern, design-patterns, php
- Language: PHP
- Size: 483 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.