Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test...

18
Monday February 4 Lecture 9

Transcript of Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test...

Page 1: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Monday February 4

Lecture 9

Page 2: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

releasedETFD

Page 3: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Once Routine EDfresh

awl - M¥7-

T →

*⇐--

←1st time

⇒ - - -

→ ①

Yetignored .

Page 4: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Approximating Once Routines a Javad ) breaking singleton .

to n

-

-

→ ¥44" di →

If- data

7¥.EE#::q:i:h*.sdda?¥÷•*÷:÷÷:÷÷g:÷÷÷dl.seeIRCI.es ) ;

Page 5: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Approximating Once Routines a Java G) Separation ofConcerns .

. Data(Data Aces

€p

data

Static- I

-

BankData dl = neeI I

f

ra¥a¥¥÷private .data

access

-

Page 6: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Singleton Pattern : Coded )

does←d§#④D's

-0¥O

⑦D=aeate-aess.ua/cexYTe's expanded

D-, ) →¥77'Estoyto

-

z- -

= -

Page 7: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

class BANK-

D- A -2Singleton Pattern : Gdek

. "

aIdataon.IE?aaaeeResukmake.#-⇒→

EOE→d⇐¥##⇒¥001€-

Page 8: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

dtaeaee"

- -.±

.

others.de?Yeanxseane

ofRANK

-

DATAusing

constructor

this

class

ACGNQdajia-A-f.cat?..da.daeaV

"

Ei÷:IEIa⑧end

Page 9: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Banian\

aeaee4B#m€BANkDATAo_A

IR→create data

.make ? X

Page 10: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

class

Account

make

↳¥dd④:LBEATd

deEtat,

data2 : B

-

D deft→ data isIida.datadata:

-HII. dataad end f

2nd timedata I = data ?

that { B- RAJ.

data

once routine To called

Page 11: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Singleton Pattern : Adem

⇒ttime,

calling 1B- RAS .

data

→- O

→- - O

Page 12: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

DATA_ACCESS +

data: DATA -- A shared data object. once create Result.make end

Invariantshared_instance: data = data

DATA +

data +

DATA_ACCESS

v: VALUE -- An example query.c -- An example command.

make -- Initialize a data object.

CLIENT_1

APPLICATION_2 +

CLIENT_2

APPLICATION_3 +

CLIENT_3

SUPPLIER_OF_SHARED_DATAAPPLICATION_1 +

Singleton Design Patternclient supplier

C) =-D ADACGONT reference type expanded type

@ Too A-D€

-

-

I

[email protected]"

data routine

Page 13: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

of : = 02

⇐ O . f Co2 )=ol := f CoD

Page 14: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

.:¥:D: teams

.

not bl a nbz a b3 → I kind-

Tbl n bz a 763 → another

kind.

Page 15: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Violation of -

fmgkchoxeprino.pl#--II

(- - tartrate

I

[-

* Tnf- rate

Page 16: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Without Inheritance : Collection of Students

JAnders : a

-aj%%"

I-# I

E- = I I

↳y,morph eaton

Page 17: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

Inheritance :

Code Reuse

TO*

Bug poor

-\

Precursor ( →→

M pretenses!E"defined adass I --

M€-01200117020

Page 18: Monday Februaryjackie/teaching/lectures/2019... · 2019. 8. 30. · tests TEST_ACCOUNT feature Test Commands for Contract Violations test_withdraw_postcondition_violation local acc:

tests

TEST_ACCOUNTfeature ­­ Test Commands for Contract Violations   test_withdraw_postcondition_violation         local             acc: BAD_ACCOUNT_WITHDRAW         do             create acc.make ("Alan", 100)            ­­ Violation of Postcondition              ­­ with tag "balance_deduced" expected             acc.withdraw (50)         end 

acc

BAD_ACCOUNT_WITHDRAWfeature ­­ Redefined Commands   withdraw (amount: INTEGER) ++         do            Precursor (amount)            ­­ Wrong Implementation            balance := balance + 2 * amount        end 

ACCOUNTfeature ­­ Commands   withdraw (amount: INTEGER)         require            non_negative_amount: amount > 0            affordable_amount: amount ≤ balance        do            balance := balance ­ amount         ensure               balance_deduced: balance = old balance ­ amount         end 

model

€00

&I

* e

a o→ ⇒ "

" "

→ -00