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!
===Genericity=== {{See also|Generic programming#Genericity in Eiffel}} A generic class is a class that varies by type (e.g. LIST [PHONE], a list of phone numbers; ACCOUNT [G->ACCOUNT_TYPE], allowing for ACCOUNT [SAVINGS] and ACCOUNT [CHECKING], etc.). Classes can be generic, to express that they are parameterized by types. Generic parameters appear in square brackets: <syntaxhighlight lang="eiffel"> class LIST [G] ... </syntaxhighlight> G is known as a "formal generic parameter". (Eiffel reserves "argument" for routines, and uses "parameter" only for generic classes.) With such a declaration G represents within the class an arbitrary type; so a function can return a value of type G, and a routine can take an argument of that type: <syntaxhighlight lang="eiffel"> item: G do ... end put (x: G) do ... end </syntaxhighlight> The <code>LIST [INTEGER]</code> and <code>LIST [WORD]</code> are "generic derivations" of this class. Permitted combinations (with <code>n: INTEGER</code>, <code>w: WORD</code>, <code>il: LIST [INTEGER]</code>, <code>wl: LIST [WORD]</code>) are: <syntaxhighlight lang="eiffel"> n := il.item wl.put (w) </syntaxhighlight> <code>INTEGER</code> and <code>WORD</code> are the "actual generic parameters" in these generic derivations. It is also possible to have 'constrained' formal parameters, for which the actual parameter must inherit from a given class, the "constraint". For example, in <syntaxhighlight lang="eiffel"> class HASH_TABLE [G, KEY -> HASHABLE] </syntaxhighlight> a derivation <code>HASH_TABLE [INTEGER, STRING]</code> is valid only if <code>STRING</code> inherits from <code>HASHABLE</code> (as it indeed does in typical Eiffel libraries). Within the class, having <code>KEY</code> constrained by <code>HASHABLE</code> means that for <code>x: KEY</code> it is possible to apply to <code>x</code> all the features of <code>HASHABLE</code>, as in <code>x.hash_code</code>.
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