This application contains an Account class that implements:
Deposit(double amount)
- increases the account’s balance with the amount;- Rules:
- the amount should always be positive
- Rules:
Withdraw(double amount)
- decreases the account’s balance;- Rules:
- the amount should always be positive
- if the amount exceeds the balance:
- the balance should be left untouched
- an exception should be thrown.
- Rules:
- Instantiating a new Account class
- Rules:
- the start amount should always be positive
- the name of the account should not be empty
- Rules:
Additionally, Program class makes use of Account.cs and it also demonstrates the use of Code Contracts that enforce Design by Contract principles.
To be able to observe the defined Design by Contract principles you would need to install Visual studio 2015 .
As well as installing Code Contracts for .NET.
Once you are done with the above, in VS you would need to:
- Go to Project > Properties > Code Contracts
- tick Perform Static Contract Checking
- untick Cache results
- set Warning Level to high
- Save
-
By Building - incorrect param values should get squiggly lines
-
Into Task List window you would be able to see the warnings that were generated
Not obeying the positive amount rule when setting up a new Account
Having this line of code will give us the Warning
As well as:
Not obeying the positive amount rule when Depositing
The DbC rules we used can be seen 👀 in the Account.cs class.
David Alves 👨🏻💻
Github
Elitsa Marinovska 👩🏻💻
Github
Attending "Discrete Mathematics" course of Software Development bachelor's degree