Encapsulation (computer programming): Difference between revisions

Content deleted Content added
No edit summary
Fixing formatting defects
Line 61:
 
<source lang="php">
class Account {
{
/**
* How much money is currently in the account
Line 72 ⟶ 71:
* @param float $currentAccountBalance Initialize account to this dollar amount
*/
public function __construct($currentAccountBalance) {
{
$this->accountBalance = $currentAccountBalance;
}
Line 82 ⟶ 80:
* @return void
*/
public function add($money) {
{
$this->accountBalance += $money;
}
Line 93 ⟶ 90:
* @return void
*/
public function withdraw($money) {
{
if ($this->accountBalance < $money) {
throw new Exception('Cannot withdraw $' . $money . ' from account as it contains $' . $this->accountBalance);
Line 105 ⟶ 101:
* @return float
*/
public function getAccountBalance() {
{
return $this->accountBalance;
}