Encapsulation (computer programming): Difference between revisions

Content deleted Content added
Sameg14 (talk | contribs)
No edit summary
Sameg14 (talk | contribs)
No edit summary
Line 61:
 
<source lang="php">
<?php
class Account
{
/**
* How much money is currently in the account
*
* @var float
*/
Line 80:
/**
* Add money to account
*
* @param float $money Dollars to add to balance
*
* @return void
*/
Line 90 ⟶ 92:
/**
* Remove money from account
*
* @param float $money Dollars to subtract from balance
*
* @throws Exception
* @return void
Line 96 ⟶ 100:
public function withdraw($money)
{
if ($this->accountBalance < $money) {
throw new Exception('Cannot withdraw $' . $money . ' from account as it contains $' . $this->accountBalance);
}
$this->accountBalance -= $money;