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
Method overriding
(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]], '''feature redefinition''' is analogous to method overriding in C++ and Java. Redefinition is one of three forms of feature adaptation classified as '''redeclaration'''. Redeclaration also covers '''effecting''', in which an implementation is provided for a feature which was deferred (abstract) in the parent class, and '''undefinition''', in which a feature that was effective (concrete) in the parent becomes deferred again in the heir class. When a feature is redefined, the feature name is kept by the heir class, but properties of the feature such as its signature, contract (respecting restrictions for [[precondition]]s and [[postcondition]]s), and/or implementation will be different in the heir. If the original feature in the parent class, called the heir feature's '''precursor''', is effective, then the redefined feature in the heir will be effective. If the precursor is deferred, the feature in the heir will be deferred.<ref name="meyer">Meyer 2009, page 572-575</ref> The intent to redefine a feature, as {{Eiffel|message}} in the example below, must be explicitly declared in the {{Eiffel|inherit}} clause of the heir class. <syntaxhighlight lang="eiffel"> class THOUGHT feature message -- Display thought message do print ("I feel like I am diagonally parked in a parallel universe.%N") end end class ADVICE inherit THOUGHT redefine message end feature message -- Precursor do print ("Warning: Dates in calendar are closer than they appear.%N") end end </syntaxhighlight> In class {{Eiffel|ADVICE}} the feature {{Eiffel|message}} is given an implementation that differs from that of its precursor in class {{Eiffel|THOUGHT}}. Consider a class which uses instances for both {{Eiffel|THOUGHT}} and {{Eiffel|ADVICE}}: <syntaxhighlight lang="eiffel"> class APPLICATION create make feature make -- Run application. do (create {THOUGHT}).message; (create {ADVICE}).message end end </syntaxhighlight> When instantiated, class {{Eiffel|APPLICATION}} produces the following output: <syntaxhighlight lang="output"> I feel like I am diagonally parked in a parallel universe. Warning: Dates in calendar are closer than they appear. </syntaxhighlight> Within a redefined feature, access to the feature's precursor can be gained by using the language keyword {{Eiffel|Precursor}}. Assume the implementation of {{Eiffel|{ADVICE}.message}} is altered as follows: <syntaxhighlight lang="eiffel"> message -- Precursor do print ("Warning: Dates in calendar are closer than they appear.%N") Precursor end </syntaxhighlight> Invocation of the feature now includes the execution of {{Eiffel|{THOUGHT}.message}}, and produces the following output: <syntaxhighlight lang="output"> Warning: Dates in calendar are closer than they appear. I feel like I am diagonally parked in a parallel universe. </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)