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
Eiffel (programming language)
(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!
===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>
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
Eiffel (programming language)
(section)
Add topic