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
Eiffel (programming language)
(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!
===Conversions=== Eiffel provides a mechanism to allow conversions between various types. The mechanisms coexists with inheritance and complements it. To avoid any confusion between the two mechanisms, the design enforces the following principle: : '''(Conversion principle) A type may not both conform and convert to another.''' For example, <code>NEWSPAPER</code> may conform to <code>PUBLICATION</code>, but <code>INTEGER</code> converts to <code>REAL</code> (and does not inherit from it). The conversion mechanism simply generalizes the ad hoc conversion rules (such as indeed between <code>INTEGER</code> and <code>REAL</code>) that exist in most programming languages, making them applicable to any type as long as the above principle is observed. For example, a <code>DATE</code> class may be declared to convert to <code>STRING</code>; this makes it possible to create a string from a date simply through <syntaxhighlight lang="eiffel"> my_string := my_date </syntaxhighlight> as a shortcut for using an explicit object creation with a conversion procedure: <syntaxhighlight lang="eiffel"> create my_string.make_from_date (my_date) </syntaxhighlight> To make the first form possible as a synonym for the second, it suffices to list the creation procedure (constructor) <code>make_from_date</code> in a <code>convert</code> clause at the beginning of the class. As another example, if there is such a conversion procedure listed from <code>TUPLE [day: INTEGER; month: STRING; year: INTEGER]</code>, then one can directly assign a tuple to a date, causing the appropriate conversion, as in <syntaxhighlight lang="eiffel"> Bastille_day := [14, "July", 1789] </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)