Lösungsvorschlag Software Architecture FS08: Unterschied zwischen den Versionen

Aus VISki
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „=1= ==1== b d f: true, since the visitor needs to know implementation details of the objects it visits ==2== b: true because class invariants are 'and'-ed, hen...“)
 
Zeile 1: Zeile 1:
=1=
+
=1 Modularity, ADT, Designy by Contract and Concurrency (8 points)=
 
==1==
 
==1==
 
b
 
b
Zeile 11: Zeile 11:
  
 
c
 
c
 +
 +
=2 Design by Contract (12 points)=
 +
<eiffel>
 +
class
 +
  BANK_ACCOUNT
 +
 +
feature
 +
withdraw(v: INTEGER) is
 +
  require TRUE
 +
do
 +
end
 +
 +
feature
 +
balance: INTEGER
 +
 +
end
 +
 +
class STUDENT_ACCOUNT inherit
 +
BANK_ACCOUNT redefine withdraw end
 +
 +
feature
 +
withdraw(v: INTEGER) is
 +
require else
 +
balance >= v
 +
do
 +
  balance := balance - v
 +
ensure
 +
  balance_altered: balance = balance - v
 +
end
 +
 +
end
 +
 +
class B_A_NORMAL inherit
 +
BANK_ACCOUNT redefine withdraw end
 +
 +
feature
 +
withdraw(v: INTEGER) is
 +
require else
 +
balance - fee >= v
 +
do
 +
  balance := balance -v
 +
ensure
 +
  balance_altered: balance = balance - v
 +
end
 +
 +
feature
 +
  fee: INTEGER
 +
 +
end
 +
 +
class B_A_BUSINESS inherit
 +
BANK_ACCOUNT redefine withdraw end
 +
 +
feature
 +
withdraw(v: INTEGER) is
 +
require else
 +
balance + credit >= v
 +
do
 +
  balance := balance -v
 +
ensure
 +
  balance_altered: balance = balance - v
 +
end
 +
 +
feature
 +
  credit: INTEGER
 +
end
 +
</eiffel>

Version vom 21. Mai 2009, 21:27 Uhr

1 Modularity, ADT, Designy by Contract and Concurrency (8 points)

1

b

d

f: true, since the visitor needs to know implementation details of the objects it visits

2

b: true because class invariants are 'and'-ed, hence stronger assertions can be introduced

c

2 Design by Contract (12 points)

<eiffel> class

 BANK_ACCOUNT

feature withdraw(v: INTEGER) is

 require TRUE

do end

feature balance: INTEGER

end

class STUDENT_ACCOUNT inherit BANK_ACCOUNT redefine withdraw end

feature withdraw(v: INTEGER) is require else balance >= v do

 balance := balance - v

ensure

 balance_altered: balance = balance - v

end

end

class B_A_NORMAL inherit BANK_ACCOUNT redefine withdraw end

feature withdraw(v: INTEGER) is require else balance - fee >= v do

 balance := balance -v

ensure

 balance_altered: balance = balance - v

end

feature

 fee: INTEGER

end

class B_A_BUSINESS inherit BANK_ACCOUNT redefine withdraw end

feature withdraw(v: INTEGER) is require else balance + credit >= v do

 balance := balance -v

ensure

 balance_altered: balance = balance - v

end

feature

 credit: INTEGER

end </eiffel>