public class Account
extends java.lang.Object
Account.xml
specification.
This uses the State Pattern (a Design Pattern from Gamma, et al.) for its
implementation. All requests are delegated to an abstract State, which
has concrete subclasses Closed and Open, which respond to certain requests
and ignore others. This is a good implementation strategy to ensure that
no information is returned by a service, when it is in an inappropriate
state.
Otherwise, the account holder is recorded in a field when the Account is opened; and the balance is recorded in another field, when amounts are deposited or withdrawn. This implementation obeys the preconditions in the specification, which treat any attempt to deposit or withdraw a zero or negative amount as an error. Errors are treated in this example as normal responses, in which bad requests have no effect, but return signal Boolean results to indicate success or failure.
Suggestions are given for how to modify the source code to seed faults deliberately, which will be detected during testing.
Constructor and Description |
---|
Account()
Creates this Account.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Boolean |
close()
Attempts to close this Account.
|
java.lang.Boolean |
deposit(int amount)
Attempts to deposit an amount in this Account.
|
java.lang.Integer |
getBalance()
Attempts to inspect the current balance.
|
java.lang.String |
getHolder()
Attempts to inspect the current holder.
|
java.lang.String |
getScenario()
Returns the last scenario that was enacted.
|
java.lang.String |
getState()
Returns the last state that was entered.
|
java.lang.Boolean |
open(java.lang.String holder)
Attempts to open this Account for a given holder.
|
java.lang.Boolean |
withdraw(int amount)
Attempts to withdraw an amount from this Account.
|
public Account()
public java.lang.String getScenario()
public java.lang.String getState()
public java.lang.Boolean open(java.lang.String holder)
holder
- the account holder.public java.lang.Boolean close()
public java.lang.Boolean deposit(int amount)
amount
- the amount to deposit.public java.lang.Boolean withdraw(int amount)
amount
- the amount to withdraw.public java.lang.Integer getBalance()
public java.lang.String getHolder()