Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Class invariant
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Eiffel==== In [[Eiffel (programming language)|Eiffel]], the class invariant appears at the end of the class following the keyword <code lang="eiffel">invariant</code>. <syntaxhighlight lang="eiffel"> class DATE create make feature {NONE} -- Initialization make (a_day: INTEGER; a_hour: INTEGER) -- Initialize `Current' with `a_day' and `a_hour'. require valid_day: a_day >= 1 and a_day <= 31 valid_hour: a_hour >= 0 and a_hour <= 23 do day := a_day hour := a_hour ensure day_set: day = a_day hour_set: hour = a_hour end feature -- Access day: INTEGER -- Day of month for `Current' hour: INTEGER -- Hour of day for `Current' feature -- Element change set_day (a_day: INTEGER) -- Set `day' to `a_day' require valid_argument: a_day >= 1 and a_day <= 31 do day := a_day ensure day_set: day = a_day end set_hour (a_hour: INTEGER) -- Set `hour' to `a_hour' require valid_argument: a_hour >= 0 and a_hour <= 23 do hour := a_hour ensure hour_set: hour = a_hour end invariant valid_day: day >= 1 and day <= 31 valid_hour: hour >= 0 and hour <= 23 end </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)