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!
====Scoping==== Unlike many object-oriented languages, but like [[Smalltalk]], Eiffel does not permit any assignment into attributes of objects, except within the features of an object, which is the practical application of the principle of [[information hiding]] or data abstraction, requiring formal interfaces for data mutation. To put it in the language of other object-oriented programming languages, all Eiffel attributes are "protected", and "setters" are needed for client objects to modify values. An upshot of this is that "setters" can and normally do, implement the invariants for which Eiffel provides syntax. While Eiffel does not allow direct access to the features of a class by a client of the class, it does allow for the definition of an "assigner command", such as: <syntaxhighlight lang="eiffel"> some_attribute: SOME_TYPE assign set_some_attribute set_some_attribute (v: VALUE_TYPE) -- Set value of some_attribute to `v'. do some_attribute := v end </syntaxhighlight> While a slight bow to the overall developer community to allow something looking like direct access (e.g. thereby breaking the Information Hiding Principle), the practice is dangerous as it hides or obfuscates the reality of a "setter" being used. In practice, it is better to redirect the call to a setter rather than implying a direct access to a feature like <code>some_attribute</code> as in the example code above.{{Citation needed|reason=Working fine in Delphi (Object Pascal) for 25 years. In Eiffel, if a setter is the only way to set an attribute, this must obviously be what is going on. How is that 'obfuscated'?|date=March 2021}} Unlike other languages, having notions of "public", "protected", "private" and so on, Eiffel uses an exporting technology to more precisely control the scoping between client and supplier classes. Feature visibility is checked statically at compile-time. For example, (below), the "{NONE}" is similar to "protected" in other languages. Scope applied this way to a "feature set" (e.g. everything below the 'feature' keyword to either the next feature set keyword or the end of the class) can be changed in descendant classes using the "export" keyword. <syntaxhighlight lang="eiffel"> feature {NONE} -- Initialization default_create -- Initialize a new `zero' decimal instance. do make_zero end </syntaxhighlight> Alternatively, the lack of a {x} export declaration implies {ANY} and is similar to the "public" scoping of other languages. <syntaxhighlight lang="eiffel"> feature -- Constants </syntaxhighlight> Finally, scoping can be selectively and precisely controlled to any class in the Eiffel project universe, such as: <syntaxhighlight lang="eiffel"> feature {DECIMAL, DCM_MA_DECIMAL_PARSER, DCM_MA_DECIMAL_HANDLER} -- Access </syntaxhighlight> Here, the compiler will allow only the classes listed between the curly braces to access the features within the feature group (e.g. {{mono|DECIMAL, DCM_MA_DECIMAL_PARSER, DCM_MA_DECIMAL_HANDLER}}).
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