case study 1– bank example - york university · a new bank account with some initial approved...
TRANSCRIPT
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 8Department of Computer Science, York University
Case Study 1– Bank example
A lot of new material illustrated via case study!RequirementsUse CasesDesign – Identify the ClassesDesign – via Tests Writing a Test for an aspect of a Use CaseTDD – Test Driven DevelopmentEiffelStudio
Clusters and ClassesTests and ETester for TDDProject Configuration and Ace filesObject quality: is_equal and equal
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 9Department of Computer Science, York University
Case Study 1 – Bank example
RequirementsOpen an account for a customer (savings or chequing)DepositWithdrawDisplay details of an accountChange LOCProduce monthly statementsPrint a list of customers…
AmbiguitiesWhat is the difference between savings and chequing?Many others …
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 10Department of Computer Science, York University
Case Study 1 – Bank example
How should we go from Requirements to Code?Two basic approaches
Plan-driven (waterfall type models)Agile (incremental approaches)
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 11Department of Computer Science, York University
Requirements to Code?
Code
How to bridge the gap between requirements and code?
???
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 12Department of Computer Science, York University
The waterfall model of the lifecycle
FEASIBILITY STUDY
REQUIREMENTS ANALYSIS
SPECIFICATION
GLOBAL DESIGN
DETAILED DESIGN
IMPLEMENTATION
DISTRIBUTION
VALIDATION & VERIFICATION
PROJECT PROGRESS
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 13Department of Computer Science, York University
Arguments for the waterfall
(After B.W. Boehm: Software engineering economics)
The activities are necessary.(But: merging of middle activities.)
The order is the right one.
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 14Department of Computer Science, York University
The waterfall model of the lifecycle
FEASIBILITY STUDY
REQUIREMENTS ANALYSIS
SPECIFICATION
GLOBAL DESIGN
DETAILED DESIGN
IMPLEMENTATION
DISTRIBUTION
VALIDATION & VERIFICATION
PROJECT TIME
DESIGN AND IMPLEMENTATION
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 15Department of Computer Science, York University
Problems with the waterfall
Late appearance of actual code.Lack of support for requirements change — and more generally for extendibility and reusability.Lack of support for the maintenance activity (70% of software costs?).Division of labor hampering Total Quality Management.Impedance mismatches.Highly synchronous model.
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 16Department of Computer Science, York University
Quality control?
Analysts
Designers
Implementers
Testers
Customers
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 17Department of Computer Science, York University
Impedance mismatches
As Management requested it. As the Project Leader defined it. As Systems designed it.
As Programming developed it. As Operations installed it. What the user wanted.(Pre-1970 cartoon; origin unknown)
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 18Department of Computer Science, York University
How to think about requirements?
Use Cases
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 19Department of Computer Science, York University
Bank Requirements – Use Cases Banking system
Open Account
Deposit
WithdrawTellerCustomer
Print Customers
System boundary
Use Case
Actors
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 20Department of Computer Science, York University
Bank Use Cases
Challenge question:
What would the Use Case diagram look like if the bank supplies ATMs in addition to tellers?
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 21Department of Computer Science, York University
Use Case – Open Account
Actors: Customer (initiator), TellerOverview: the customer applies for and is granted a new bank account with some initial approved line of credit. The teller logs on to the system, selects open account , and supplies the new account details. The system prints a copy of the contents of the new account with the date, which the teller hands to the customer.
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 22Department of Computer Science, York University
Design of Bank – Identify Classes
TELLERCUSTOMERSAVINGS_ACCOUNTCHEQUING_ACCOUNTMAIN_MENUBALANCE_INQUIRYINTEREST_RATE ………
Where do we start?
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 23Department of Computer Science, York University
Test Driven Development
1. Write a little TestTest will not work initially (there is no code)Might not even compile
2. Make the Test work quicklyCommit whatever sins are necessary in the process (e.g. duplication in the code)
3. RefactorEliminate the duplication created in merely getting the test to work
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 24Department of Computer Science, York University
TDD
Goal: clean code that worksClean code
Simple ??
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 25Department of Computer Science, York University
EiffelStudio – create a new project
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 26Department of Computer Science, York University
Call the new project bank
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 27Department of Computer Science, York University
Compile and Run
print(“hello world!”)
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 28Department of Computer Science, York University
Compile often!
Always start with a compiled systemNew project wizardCopy an existing system
A compiled system is needed for browsingCompile often!
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 29Department of Computer Science, York University
ETester – Create a tests cluster
www.cs.yorku.ca/eiffel/etester
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 30Department of Computer Science, York University
Create class account_test
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 31Department of Computer Science, York University
Clusters and Classes
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 32Department of Computer Science, York University
Ace file – Directory Structure
Directory (cluster)
Class file
d3d2d1
d4
f3.ef1.e
d0
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 33Department of Computer Science, York University
Ace File – Ace.ace
system"bank2“
rootroot_class: make
defaultprecompiled ("C:\Eiffel54\precomp\spec\windows\base-time-etester")assertion (check)assertion (require) …
clusterroot_cluster: "C:\eiffel54_projects\bank2"
all tests: ".\tests“
library base: "$ISE_EIFFEL\library\base"exclude
"table_eiffel3"; "desc"; end …
end
http://www.cs.yorku.ca/eiffel/precompiled
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 34Department of Computer Science, York University
Project Configuration (Ace file)
Root Class
ACCOUNT_TEST
All contracts turned on
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 35Department of Computer Science, York University
Write Test
test_create_account: BOOLEAN islocal
c: CUSTOMERdo
comment("test_create_account")create c.make("Archie Fox")Result := equal(c.name, "Archie Fox")
end
Error code: VTCTError: type is based on unknown class.What to do: use an identifier that is the name of a class in the
universe.Class: ACCOUNT_TESTUnknown class name: CUSTOMER
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 36Department of Computer Science, York University
The Test specifies a Design
CUSTOMER
name: STRING
invariantname /= Void
ANY
is_equal (other: like Current): BOOLEAN frozen equal (some: ANY; other: like some): BOOLEAN
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 37Department of Computer Science, York University
EiffelStudio – create feature tool
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 38Department of Computer Science, York University
customer.e
indexingdescription: "A bank customer“
class CUSTOMER createset_name
feature -- Element changeset_name (a_name: STRING) is
-- Create a custor. Set `name' to `a_name'.require
a_name_not_void: a_name /= Voiddo
name := a_nameensure
name_assigned: name = a_nameend
feature -- Accessname: STRING
-- of customerinvariant
name_not_void: name /= Voidend
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 39Department of Computer Science, York University
ETester GUI – Green bar
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 40Department of Computer Science, York University
Test: A customer with a savings account
test_create_customer_with_account: BOOLEAN islocal
a1,a2: SAVINGS_ACCOUNTc: CUSTOMERinitial_deposit: REAL
doinitial_deposit := 500create a1.make(initial_deposit)check a1.balance = initial_deposit endcreate c.make(a1, "Archie Fox")a2 := c.accountResult := equal(c.name, "Archie Fox") and
a2 = a1 and a2.balance = initial_depositend
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 41Department of Computer Science, York University
Red bar
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 42Department of Computer Science, York University
Use debugger to find problem
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 43Department of Computer Science, York University
EiffelStudio – BON tool
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 44Department of Computer Science, York University
Client-Supplier relationship
SAVINGS_ACCOUNT
balance: REAL invariant
balance >= 0
account
CUSTOMER
name: STRING account: ACCOUNT
invariantname /= Void account /= Void
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 45Department of Computer Science, York University
Open Account Use case (revisited)
Actors: Customer (initiator), TellerOverview: the customer applies for and is granted a new bank account with some initial approved line of credit. The teller logs on to the system, selects open account , and supplies the new account details. The system prints a copy of the contents of the new account with the date, which the teller hands to the customer.
We have not yet dealt with the LOC, system menu and the receipt. We leave this as an exercise.
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 46Department of Computer Science, York University
Withdraw Use Case
Actors: Customer (initiator) and TellerOverview: The customer provides the teller with an account number and a withdrawal amount. The teller selects `withdraw-request’ from the system menu, and enters the data. The System debits the account by the requested withdrawal amount, and prints a receipt with the date and the amount, which the teller gives to the customer.
Question: What happens if there is not enough money in the account to withdraw?
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 47Department of Computer Science, York University
test_withdraw
test_withdraw: BOOLEAN islocal
sa1, sa2: SAVINGS_ACCOUNTinitial_deposit: REAL
docomment("test_withdraw")initial_deposit := 500create sa1.make(initial_deposit)create sa2.make(200)sa1.withdraw(300)Result := equal(sa1, sa2)
end
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 48Department of Computer Science, York University
Bank design (BON static diagram)
ANY
is_equal(other: like Current): BOOLEAN frozen equal(some: ANY; other: like some): BOOLEAN
CUSTOMER
name: STRING account: ACCOUNT
invariantname /= Void account /= Void
account
SAVINGS_ACCOUNT
balance: REAL withdraw (amount: REAL)
require amount > 0 amount <= balance
ensure balance = old balance - amount
invariantbalance >= 0
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 49Department of Computer Science, York University
EiffelStudio feature tool – withdraw
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 50Department of Computer Science, York University
Run tests
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 51Department of Computer Science, York University
Object equality
sa1, sa2: SAVINGS_ACCOUNT
Result := equal(sa1, sa2)
equal is inherited from ANYIn this case, no redefinition is neededYou redefine equal by redefining is_equal
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 52Department of Computer Science, York University
is_equal
is_equal (other: like Current): BOOLEAN is-- Is `other' attached to an object considered-- equal to current object?
requireother_not_void: other /= Void
do-- call C version of equality
ensuresymmetric:
Result implies other.is_equal (Current)consistent:
standard_is_equal (other) implies Resultend
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 53Department of Computer Science, York University
equal
frozen equal (some: ANY; other: like some): BOOLEAN is-- Are `some' and `other' either both void or attached-- to objects considered equal?
doif some = Void then
Result := other = Voidelse
Result := other /= Void and thensome.is_equal (other)
endensure
definition: Result = (some = Void and other = Void)
or else((some /= Void and other /= Void)
and thensome.is_equal (other))
end
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 54Department of Computer Science, York University
withdraw_negative
test_withdraw_negative_amount: BOOLEAN islocal
a1, a2: SAVINGS_ACCOUNTinitial_deposit: REAL
docomment("test_withdraw_negative_amount")initial_deposit := 500create a1.make(initial_deposit)create a2.make(200)a1.withdraw(-100) – what happens here?Result := equal(a1, a2)
end
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 55Department of Computer Science, York University
Contract Violation
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 56Department of Computer Science, York University
Violation Test Case
In make:add_violation_case (agent test_withdraw_negative_amount)
test_withdraw_negative_amount islocal
a: SAVINGS_ACCOUNTinitial_deposit: REAL
docomment("test_withdraw_negative_amount")initial_deposit := 500create a.make(initial_deposit)a.withdraw(-100) –- a violation here is expected
end
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 57Department of Computer Science, York University
(expected) Violation case
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 58Department of Computer Science, York University
BON static diagram
Slides based on Object Oriented Software Construction 29/12/2003 3:22 PM 59Department of Computer Science, York University
Bank Challenge question
Add a deposit featureHow would you write the test
New Requirement: monthly statementThe System must generate a monthly statement for the customerEach deposit or withdrawal must be date stampedInterest must be added or charged as applicable
New Requirement: Print all bank customers in alphabetical orderPrint customers with largest balances in order