Commit b091ed35 authored by Mathias Verraes's avatar Mathias Verraes
Browse files

added paragraph on object creation, used shortcut notation everywhere

parent 41821ead
......@@ -17,6 +17,17 @@ This is a PHP implementation of the Money pattern, as described in [Fowler2002]:
Examples
========
Creation
--------
All amounts are represented in the smallest unit (eg. cents), so USD 5.00 is written as
<?php
$fiver = new Money(500, new USD);
// or shorter:
$fiver = Money::USD(500);
Allocation
----------
......@@ -27,7 +38,7 @@ down to 3 and 1 cent leaves me 1 cent. Apart from re-investing that cent in the
is to keep handing out the remainder until all money is spent. In other words:
<?php
$profit = new Money(5, new EUR);
$profit = Money::EUR(5);
list($my_cut, $investors_cut) = $profit->allocate(70, 30);
// $my_cut is 4 cents, $investors_cut is 1 cent
......@@ -41,12 +52,12 @@ Immutability
Jim and Hannah both want to buy a copy of book priced at EUR 25.
<?php
$jim_price = $hannah_price = new Money(2500, new EUR);
$jim_price = $hannah_price = Money::EUR(2500);
Jim has a coupon for EUR 5.
<?php
$coupon = new Money(500, new EUR);
$coupon = Money::EUR(500);
$jim_price->subtract($coupon);
Because $jim_price and $hannah_price are the same object, you'd expect Hannah to now have the reduced
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment