OOP Design for an Economy

Posted by waiwai933 on Stack Overflow See other posts from Stack Overflow or by waiwai933
Published on 2010-04-17T02:14:38Z Indexed on 2010/04/17 2:23 UTC
Read the original article Hit count: 434

Filed under:
|

Not sure where to start, so I'm just going to plow in. Let's say I'm trying to represent an economy in OOP. A basic design I've come up with is:

class Person{
  int $money; // Money someone has in wallet/purse
  int $bank_account_id;

  function getAmountOfMoney()
  function addMoney($amountToAdd)
  function subtractMoney($amountToSubtract)
}

class BankAccount{
  int $money; // Money in Bank Account
  int $interest_per_year;

  function giveInterest()
  function depositMoney() // Calls $person->subtractMoney()
  function withdrawMoney() // Calls $person->addMoney()

}

Are there any design flaws here?

© Stack Overflow or respective owner

Related posts about oop

Related posts about object-oriented-design