Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Precondition
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
==In object-oriented programming== Preconditions in [[Object-oriented programming|object-oriented]] software development are an essential part of [[design by contract]]. Design by contract also includes notions of [[postcondition]] and [[class invariant]]. The precondition for any routine defines any constraints on object state which are necessary for successful execution. From the program developer's viewpoint, this constitutes the routine caller's portion of the contract. The caller then is obliged to ensure that the precondition holds prior to calling the routine. The reward for the caller's effort is expressed in the called routine's [[postcondition]].<ref>[[Bertrand Meyer|Meyer, Bertrand]], ''[[Object-Oriented Software Construction]], second edition,'' [[Prentice Hall]], 1997, p. 342.</ref> ===Eiffel example=== The routine in the following example written in [[Eiffel (programming language)|Eiffel]] takes as an argument an integer which must be a valid value for an hour of the day, i. e., 0 through 23, inclusively. The precondition follows the keyword <code>require</code>. It specifies that the argument must be greater than or equal to zero and less than or equal to 23. The tag "<code>valid_argument:</code>" describes this precondition clause and serves to identify it in case of a runtime precondition violation. <syntaxhighlight lang="eiffel"> set_hour (a_hour: INTEGER) -- Set `hour' to `a_hour' require valid_argument: 0 <= a_hour and a_hour <= 23 do hour := a_hour ensure hour_set: hour = a_hour end </syntaxhighlight> ===Preconditions and inheritance=== In the presence of inheritance, the routines inherited by descendant classes (subclasses) do so with their preconditions in force. This means that any implementations or redefinitions of inherited routines also have to be written to comply with their inherited contract. Preconditions can be modified in redefined routines, but they may only be weakened.<ref>Meyer, 1997, pp. 570β573.</ref> That is, the redefined routine may lessen the obligation of the client, but not increase it.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Precondition
(section)
Add topic