Practice producing best code when there is minimal time pressure.
Practice Object-Oriented design and my TDD skills.
Using the acceptance criteria I first started the challange by diagramming user interaction using UML interaction diagrams. Following the interaction diagram I created class diagrams to help me to identify my class attributes and methods. Through diagramming, I came up with four classes:
BankAccount
- that allows users to deposit and withdraw money from their account;
Transaction
- will keep track of each deposit and withdrawal request to the account. Here the date will be recorded with each transaction and stored in a history. This brought about the 3rd class,
TransactionHistory
- stores the transactions generated by Transaction. The final class,
BankStatement
- allows for the printing of all account transaction activities.
The approach of separating into four classes is to allow single responsibilities, relieving the burden of one class having too much work to do.
Following diagramming I then proceeded with writing initial simple spec tests so user can deposit and withdraw money. After successful implementation, I then refactored code to try keep DRY and lint using rubocop.
Given a client makes a deposit of 1000 on 10-01-2012
And a deposit of 2000 on 13-01-2012
And a withdrawal of 500 on 14-01-2012
When she prints her bank statement
Then she would see:
date || credit || debit || balance
14/01/2012 || || 500.00|| 2500.00
13/01/2012 || 2000.00|| || 3000.00
10/01/2012 || 1000.00|| || 1000.00
As an account holder
So I can add money to my account
I would like to deposit money
As an account holder
So I can take money from my account
I would like to withdraw money
As an account holder
So I can view my transactions
I would like to print my account statement with (date, amount, balance) of withdrawals and deposits
$ git clone https://github.com/learningtocode101/bank_tech_test.git
$ bundle install
$ rspec (to check all tests pass)
$ irb or pry (to interact with app)
[1] pry(main)> require './lib/transaction'
=> true
[2] pry(main)> require './lib/transactionhistory'
=> true
[3] pry(main)> require './lib/bankstatement'
=> true
[4] pry(main)> require './lib/bankaccount'
=> true
[5] pry(main)> account = BankAccount.new
=> #<BankAccount:0x00007fca30305e60 @balance=0.0, @statement=BankStatement, @transactions=#<TransactionHistory:0x00007fca30305e38 @history=[]>>
[6] pry(main)> account.deposit(500)
=> [#<Transaction:0x00007fead255ac70 @balance=500.0, @deposit=500, @time=2019-02-12 19:13:41 +0000, @withdrawal=nil>]
[7] pry(main)> account.withdraw(200)
=> [#<Transaction:0x00007fead255ac70 @balance=500.0, @deposit=500, @time=2019-02-12 19:13:41 +0000, @withdrawal=nil>,
#<Transaction:0x00007fead24d0638 @balance=300.0, @deposit=nil, @time=2019-02-12 19:14:26 +0000, @withdrawal=200>]
[8] pry(main)> account.view_statement
date || credit || debit || balance
12/02/2019 || 500.0 || || 500.0
12/02/2019 || || 200.0 || 300.0