diff options
Diffstat (limited to 'bank-eiffel/account.e')
| -rw-r--r-- | bank-eiffel/account.e | 134 |
1 files changed, 86 insertions, 48 deletions
diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 3ef7a8b..a6e30ef 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e | |||
| @@ -1,31 +1,13 @@ | |||
| 1 | note | ||
| 2 | description: "Summary description for {ACCOUNT}." | ||
| 3 | author: "" | ||
| 4 | date: "$Date$" | ||
| 5 | revision: "$Revision$" | ||
| 6 | |||
| 7 | class | 1 | class |
| 8 | ACCOUNT | 2 | ACCOUNT |
| 9 | 3 | ||
| 10 | create | 4 | create |
| 11 | make | 5 | make |
| 12 | 6 | ||
| 13 | -- TODO | ||
| 14 | -- interest should defined by bank (via make?) | ||
| 15 | -- add more checks to invariant (like balance >= creditline) ? | ||
| 16 | -- check if balance is a getter and not a setter (doesn't has an assign) | ||
| 17 | -- + check if authorized_signers is a getter and not a setter (it doesn't has an assign) | ||
| 18 | -- -> if not: add a getter (via Result or so..) and move them to {NONE} | ||
| 19 | -- much other stuff to test like: lower creditline so that balance will be invalid | ||
| 20 | |||
| 21 | feature -- Access | 7 | feature -- Access |
| 22 | 8 | ||
| 23 | transfer_minamount: REAL_64 assign set_transfer_minamount | 9 | balance: REAL_64 |
| 24 | -- Mindestbetrag für jede Einzahlung, Auszahlung und Überweisung | 10 | -- Kontostand |
| 25 | |||
| 26 | authorized_signers: ARRAYED_SET [PERSON] | ||
| 27 | -- Zeichnungsberechtigte | ||
| 28 | attribute Result := ({like authorized_signers}).default end --| Remove line when Void Safety is properly set | ||
| 29 | 11 | ||
| 30 | creditline: REAL_64 assign set_creditline | 12 | creditline: REAL_64 assign set_creditline |
| 31 | -- Kreditrahmen | 13 | -- Kreditrahmen |
| @@ -36,25 +18,57 @@ feature -- Access | |||
| 36 | interest_debit: REAL_64 assign set_interest_debit | 18 | interest_debit: REAL_64 assign set_interest_debit |
| 37 | -- Sollverzinsung | 19 | -- Sollverzinsung |
| 38 | 20 | ||
| 39 | balance: REAL_64 | 21 | transfer_minamount: REAL_64 assign set_transfer_minamount |
| 40 | -- Kontostand | 22 | -- Mindestbetrag fuer jede Einzahlung, Auszahlung und Ueberweisung |
| 23 | |||
| 24 | feature {NONE} -- Implementation | ||
| 25 | |||
| 26 | range: detachable TUPLE [min: REAL_64; max: REAL_64] | ||
| 27 | |||
| 28 | creditline_range: attached like range | ||
| 29 | -- min/max for creditline | ||
| 30 | |||
| 31 | interest_deposit_range: attached like range | ||
| 32 | -- min/max for interest_deposit | ||
| 33 | |||
| 34 | interest_debit_range: attached like range | ||
| 35 | -- min/max for interest_debit | ||
| 36 | |||
| 37 | authorized_signers: ARRAYED_SET [PERSON] | ||
| 38 | -- Zeichnungsberechtigte | ||
| 41 | 39 | ||
| 42 | feature {NONE} -- Initialization | 40 | feature {NONE} -- Initialization |
| 43 | 41 | ||
| 44 | make (an_authorized_signer: PERSON) | 42 | make (an_authorized_signer: PERSON; |
| 43 | an_interest_deposit: like interest_deposit; | ||
| 44 | an_interest_debit: like interest_debit; | ||
| 45 | a_credit_line: like creditline; | ||
| 46 | an_interest_deposit_range: like interest_deposit_range; | ||
| 47 | an_interest_debit_range: like interest_debit_range; | ||
| 48 | a_credit_line_range: like creditline_range) | ||
| 49 | require | ||
| 50 | a_credit_line_range.min < a_credit_line_range.max | ||
| 51 | an_interest_debit_range.min < an_interest_debit_range.max | ||
| 52 | an_interest_deposit_range.min < an_interest_deposit_range.max | ||
| 45 | do | 53 | do |
| 46 | create authorized_signers.make(1) | 54 | create authorized_signers.make(1) |
| 47 | add_authorized_signer (an_authorized_signer) | 55 | add_authorized_signer (an_authorized_signer) |
| 48 | transfer_minamount := 2 | 56 | creditline := a_credit_line |
| 49 | balance := 0 | 57 | interest_debit := an_interest_debit |
| 58 | interest_deposit := an_interest_deposit | ||
| 59 | interest_deposit_range := an_interest_deposit_range | ||
| 60 | interest_debit_range := an_interest_debit_range | ||
| 61 | creditline_range := a_credit_line_range | ||
| 62 | |||
| 63 | set_default_transfer_minamount | ||
| 64 | balance := 0.0 | ||
| 50 | end | 65 | end |
| 51 | 66 | ||
| 52 | feature -- Basic operations | 67 | feature -- Basic operations |
| 53 | 68 | ||
| 54 | deposit (an_amount: like transfer_minamount; an_authorized_signer: PERSON) | 69 | deposit (an_amount: like transfer_minamount; an_authorized_signer: PERSON) |
| 55 | require | 70 | require |
| 56 | an_authorized_signer_authorized: authorized_signers.has (an_authorized_signer) | 71 | an_authorized_signer_authorized: get_authorized_signers.has (an_authorized_signer) |
| 57 | an_amount_positive: an_amount > 0.0 | ||
| 58 | transfer_minamount_ok: an_amount >= transfer_minamount | 72 | transfer_minamount_ok: an_amount >= transfer_minamount |
| 59 | do | 73 | do |
| 60 | balance := balance + an_amount | 74 | balance := balance + an_amount |
| @@ -65,50 +79,64 @@ feature -- Basic operations | |||
| 65 | 79 | ||
| 66 | withdraw (an_amount: like transfer_minamount; an_authorized_signer: PERSON) | 80 | withdraw (an_amount: like transfer_minamount; an_authorized_signer: PERSON) |
| 67 | require | 81 | require |
| 68 | an_authorized_signer_authorized: authorized_signers.has (an_authorized_signer) | 82 | an_authorized_signer_authorized: get_authorized_signers.has (an_authorized_signer) |
| 69 | an_amount_positive: an_amount > 0.0 | ||
| 70 | transfer_minamount_ok: an_amount >= transfer_minamount | 83 | transfer_minamount_ok: an_amount >= transfer_minamount |
| 84 | balance_beneath_creditline: balance - an_amount >= creditline | ||
| 71 | do | 85 | do |
| 72 | balance := balance - an_amount | 86 | balance := balance - an_amount |
| 73 | ensure | 87 | ensure |
| 88 | balance_beneath_creditline: balance >= creditline | ||
| 74 | balance_decreased: balance < old balance | 89 | balance_decreased: balance < old balance |
| 75 | withdrawed: balance = old balance - an_amount | 90 | withdrawed: balance = old balance - an_amount |
| 76 | creditline_ok: balance >= creditline | ||
| 77 | end | 91 | end |
| 78 | 92 | ||
| 79 | transfer(an_amount: like transfer_minamount; an_authorized_signer: PERSON; an_account: like Current; another_authorized_signer: PERSON;) | 93 | transfer(an_amount: like transfer_minamount; an_authorized_signer: PERSON; |
| 94 | an_account: like Current; another_authorized_signer: PERSON) | ||
| 80 | require | 95 | require |
| 81 | an_account_attached: an_account /= Void | 96 | recipient_account_not_same: Current /= an_account |
| 82 | do | 97 | do |
| 83 | withdraw (an_amount, an_authorized_signer) | 98 | withdraw (an_amount, an_authorized_signer) |
| 84 | an_account.deposit (an_amount, another_authorized_signer) | 99 | an_account.deposit (an_amount, another_authorized_signer) |
| 85 | end | 100 | end |
| 86 | 101 | ||
| 87 | add_authorized_signer (an_authorized_signer: PERSON) | 102 | add_authorized_signer (an_authorized_signer: PERSON) |
| 88 | require | ||
| 89 | an_authorized_signer_attached: an_authorized_signer /= Void | ||
| 90 | an_authorized_signer_notinlist: not authorized_signers.has (an_authorized_signer) | ||
| 91 | do | 103 | do |
| 92 | authorized_signers.put (an_authorized_signer) | 104 | if not authorized_signers.has (an_authorized_signer) then |
| 105 | authorized_signers.put (an_authorized_signer) | ||
| 106 | end | ||
| 93 | ensure | 107 | ensure |
| 94 | authorized_signers_assigned: authorized_signers.has (an_authorized_signer) | 108 | authorized_signers_assigned: authorized_signers.has (an_authorized_signer) |
| 95 | end | 109 | end |
| 96 | 110 | ||
| 97 | remove_authorized_signer (an_authorized_signer: PERSON) | 111 | remove_authorized_signer (an_authorized_signer: PERSON) |
| 98 | require | 112 | require |
| 99 | an_authorized_signer_attached: an_authorized_signer /= Void | 113 | authorized_signer_exists: (get_authorized_signers.has (an_authorized_signer)) |
| 100 | an_authorized_signer_inlist: authorized_signers.has (an_authorized_signer) | 114 | authorized_signers_not_empty: get_authorized_signers.count >= 2 |
| 101 | authorized_signers_never_empty: authorized_signers.count >= 2 | ||
| 102 | do | 115 | do |
| 103 | authorized_signers.prune (an_authorized_signer) | 116 | authorized_signers.prune (an_authorized_signer) |
| 104 | ensure | 117 | ensure |
| 105 | authorized_signers_assigned: not authorized_signers.has (an_authorized_signer) | 118 | authorized_signers_assigned: not authorized_signers.has (an_authorized_signer) |
| 106 | end | 119 | end |
| 107 | 120 | ||
| 121 | get_authorized_signers: FINITE [PERSON] | ||
| 122 | do | ||
| 123 | Result := authorized_signers | ||
| 124 | end | ||
| 125 | |||
| 126 | advance | ||
| 127 | do | ||
| 128 | if balance < 0.0 then | ||
| 129 | -- debit | ||
| 130 | balance := balance + (balance * interest_debit) | ||
| 131 | else | ||
| 132 | -- deposit | ||
| 133 | balance := balance + (balance * interest_deposit) | ||
| 134 | end | ||
| 135 | end | ||
| 136 | |||
| 108 | feature {NONE} -- Implementation | 137 | feature {NONE} -- Implementation |
| 109 | 138 | ||
| 110 | set_transfer_minamount (a_transfer_minamount: like transfer_minamount) | 139 | set_transfer_minamount (a_transfer_minamount: like transfer_minamount) |
| 111 | -- Assign `transfer_minamount' with `a_transfer_minamount'. | ||
| 112 | require | 140 | require |
| 113 | a_transfer_minamount_positive: a_transfer_minamount > 0.0 | 141 | a_transfer_minamount_positive: a_transfer_minamount > 0.0 |
| 114 | do | 142 | do |
| @@ -117,8 +145,15 @@ feature {NONE} -- Implementation | |||
| 117 | transfer_minamount_assigned: transfer_minamount = a_transfer_minamount | 145 | transfer_minamount_assigned: transfer_minamount = a_transfer_minamount |
| 118 | end | 146 | end |
| 119 | 147 | ||
| 148 | set_default_transfer_minamount | ||
| 149 | do | ||
| 150 | set_transfer_minamount (2.0) | ||
| 151 | end | ||
| 152 | |||
| 120 | set_creditline (a_creditline: like creditline) | 153 | set_creditline (a_creditline: like creditline) |
| 121 | -- Assign `creditline' with `a_creditline'. | 154 | require |
| 155 | a_creditline_within_bounds: a_creditline >= creditline_range.min | ||
| 156 | and a_creditline <= creditline_range.max | ||
| 122 | do | 157 | do |
| 123 | creditline := a_creditline | 158 | creditline := a_creditline |
| 124 | ensure | 159 | ensure |
| @@ -126,9 +161,9 @@ feature {NONE} -- Implementation | |||
| 126 | end | 161 | end |
| 127 | 162 | ||
| 128 | set_interest_deposit (an_interest_deposit: like interest_deposit) | 163 | set_interest_deposit (an_interest_deposit: like interest_deposit) |
| 129 | -- Assign `interest_deposit' with `an_interest_deposit'. | ||
| 130 | require | 164 | require |
| 131 | an_interest_deposit_within_bounds: an_interest_deposit >= 0.0 and an_interest_deposit <= 1.0 | 165 | an_interest_deposit_within_bounds: interest_deposit >= interest_deposit_range.min |
| 166 | and interest_deposit <= interest_deposit_range.max | ||
| 132 | do | 167 | do |
| 133 | interest_deposit := an_interest_deposit | 168 | interest_deposit := an_interest_deposit |
| 134 | ensure | 169 | ensure |
| @@ -136,9 +171,9 @@ feature {NONE} -- Implementation | |||
| 136 | end | 171 | end |
| 137 | 172 | ||
| 138 | set_interest_debit (an_interest_debit: like interest_debit) | 173 | set_interest_debit (an_interest_debit: like interest_debit) |
| 139 | -- Assign `interest_debit' with `an_interest_debit'. | ||
| 140 | require | 174 | require |
| 141 | an_interest_debit_within_bounds: an_interest_debit >= 0.0 and an_interest_debit <= 1.0 | 175 | an_interest_deposit_within_bounds: interest_debit >= interest_debit_range.min |
| 176 | and interest_debit <= interest_debit_range.max | ||
| 142 | do | 177 | do |
| 143 | interest_debit := an_interest_debit | 178 | interest_debit := an_interest_debit |
| 144 | ensure | 179 | ensure |
| @@ -146,9 +181,12 @@ feature {NONE} -- Implementation | |||
| 146 | end | 181 | end |
| 147 | 182 | ||
| 148 | invariant | 183 | invariant |
| 149 | interest_debit_within_bounds: interest_debit >= 0.0 and interest_debit <= 1.0 | ||
| 150 | interest_deposit_within_bounds: interest_deposit >= 0.0 and interest_deposit <= 1.0 | ||
| 151 | authorized_signers_attached: authorized_signers /= Void | ||
| 152 | authorized_signers_not_empty: authorized_signers.count > 0 | 184 | authorized_signers_not_empty: authorized_signers.count > 0 |
| 153 | transfer_minamount_positive: transfer_minamount > 0.0 | 185 | transfer_minamount_positive: transfer_minamount > 0.0 |
| 186 | creditline_within_bounds: creditline >= creditline_range.min | ||
| 187 | and creditline <= creditline_range.max | ||
| 188 | interest_debit_within_bounds: interest_debit >= interest_debit_range.min | ||
| 189 | and interest_debit <= interest_debit_range.max | ||
| 190 | interest_deposit_within_bounds: interest_deposit >= interest_deposit_range.min | ||
| 191 | and interest_deposit <= interest_deposit_range.max | ||
| 154 | end | 192 | end |
