mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-08 15:52:26 +01:00
Added section on non-object calls.
Author:halw Date:2010-08-28T16:19:32.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@668 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -111,6 +111,31 @@ One final twist is the mechanism for creating instances of formal generic parame
|
||||
to make <code>G</code> constrained by <code>T</code>, as we learned before, and specify that any actual generic parameter must have <code>cp</code> among its creation procedures. Then it's permitted to use <code>create x.cp</code>, with arguments if required by <code>cp</code>, since it is guaranteed to be safe. The mechanism is very general since you may use <code>ANY</code> for <code>T</code> and <code>default_create</code> for <code>cp</code>. The only requirement on <code>cp</code> is that it must be a procedure of <code>T</code>, not necessarily a creation procedure; this permits using the mechanism even if <code>T</code> is deferred, a common occurrence. It's only descendants of <code>T</code> that must make <code>cp</code> a creation procedure, by listing it in the <code>create</code> clause, if they want to serve as actual generic parameters for <code>C</code>.
|
||||
|
||||
|
||||
==Non-object calls==
|
||||
|
||||
The Eiffel model for object-oriented computation involves the application of some feature <code>f</code> to some object <code>x</code>, and possibly passing arguments <code>a</code>:
|
||||
|
||||
<code>
|
||||
x.f (a)
|
||||
</code>
|
||||
|
||||
This type of feature call is known as an '''object call''' because it applies the feature to a target object, in this case <code>x</code>. However, under certain circumstances we may apply a feature of a class in a fashion that does not involve a target object. This type of call is a '''non-object call'''. In place of the target object, the syntax of the non-object call uses the type on which the feature can be found.
|
||||
|
||||
<code>
|
||||
circumference := radius * 2.0 * {MATH_CONST}.Pi
|
||||
</code>
|
||||
|
||||
In the sample above, the call to feature <code>{MATH_CONST}.Pi</code> is a non-object call. This case illustrates one of the primary uses of non-object calls. Because of non-object calls, constants do not have to be part of a shared object or features inherited by the classes that use them.
|
||||
|
||||
The other primary use is for external features. One example is when we use Microsoft .NET classes from Eiffel code and have to access mechanisms for which there is no direct analog in Eiffel. Microsoft .NET supports so-called "static" methods and enumeration types. To access these, we use non-object calls. In the example below, a non-object call is used to access the enumeration <code lang="text">CreateNew</code> from the .NET enumeration type <code lang="text">System.IO.FileMode</code>.
|
||||
|
||||
<code>
|
||||
create my_file_stream.make ("my_file.txt", {FILE_MODE}.create_new)
|
||||
</code>
|
||||
|
||||
The validity of a non-object call is restricted in ways that mirror these primary uses. That is, any feature called in a non-object call must be either a constant attribute or an external feature. See the [[ECMA Standard 367|ISO/ECMA Eiffel standard document]] for additional details.
|
||||
|
||||
|
||||
==Tuple types==
|
||||
|
||||
The study of genericity described arrays. Another common kind of container objects bears some resemblance to arrays: sequences, or "tuples", of elements of specified types. The difference is that all elements of an array were of the same type, or a conforming one, whereas for tuples you will specify the types we want for each relevant element. A typical tuple type is of the form
|
||||
|
||||
Reference in New Issue
Block a user