contract


How to extend a feature's require conditions in Eiffel?


I have a class, which redefines the copy feature from ANY. I would like to add a new require condition, but I get this error:
Assertion in redeclaration uses just 'require' or 'ensure'. invalid precondition feature 'copy'
Code:
copy ( other : like Current )
require
size_is_enough: Current.max_size >= other.count
do
-- ...
end
Explanation:
This class contains an array, and I would like to check before copying, if the object has enough space for them
Preconditions in feature redeclarations can be weakened in Eiffel by using require else instead of require (for postconditions it would be ensure then instead of ensure). The new effective precondition will be a combination of the original one and the new one. For example, if there is a feature
foo
require
A
that is redeclared as
foo
require else
B
then the effective precondition will be A or else B. In other words, a precondition of a redeclaration is always weaker than of the original feature.
The same applies to the precondition of the feature copy: it can only become weaker. It means that you cannot check that the array size of the current object is larger than of the other one. The precondition of the redeclaration will only be checked when the original precondition is not satisfied, i.e. when the type of the other object is different from the type of the current one. In other words, you are trying to strengthen the precondition and this is impossible.
One option is to use a different feature instead of copy, another is to resize storage of the current object if required. In both cases the precondition of the feature copy remains unchanged.

Related Links

How to extend a feature's require conditions in Eiffel?
should a contract draft be reviewed? [closed]
Should i program alongside a webdeveloper if i am not a webdeveloper?

Categories

HOME
service-worker
grok
polymer
rdbms
rsa
yahoo-finance
r-googlesheets
database-normalization
soa
regular-language
settings
iis-6
joomla3.0
extjs4.2
watson-conversation
jxl
supervisor
mongodb-csharp
gruntfile
event-sourcing
asp.net-mvc-viewmodel
sse
sencha-touch
asp.net-core-webapi
microsoft-ocr
poedit
undertow
dataflow-diagram
displaytag
google-api-client
delimiter
sinch
winpe
corenlp-server
database-comparison
linkedhashmap
contacts
openwhisk
least-squares
getlasterror
roblox
dm-script
node-mssql
plr
knime
twilio-click-to-call
activeperl
podscms
spring-data-couchbase
sundials
cmp
reporting-services-2012
actor-platform
ziparchive
pacemaker
dup
observablecollection
qiime
cfchart
angular-ui-typeahead
bizagi
nio2
kendo-upload
concept-insights
ascii-art
atan2
avisynth
.bash-profile
doctype
haskell-warp
skspritenode
matlab-deployment
packet-sniffers
sip-server
easyrtc
file-not-found
dsym
multiautocompletetextview
windows-phone-8-sdk
tlf
octal
fb.ui
qtconcurrent
cgimage
denied
workflow-services
google-floodlight
listactivity
google-ajax-api
svk
jqueryform
isapi-extension
application-verifier
data-mapping
alsb
sqlobject
firefox-3
image-capture

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App