From 2930e4f44b0fb5c9901d189265458dc64bbac7c1 Mon Sep 17 00:00:00 2001 From: halw Date: Sat, 17 Sep 2011 02:24:59 +0000 Subject: [PATCH] Author:halw Date:2011-09-17T02:24:59.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@975 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../et-other-mechanisms.wiki | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/documentation/current/method/eiffel-tutorial-et/et-other-mechanisms.wiki b/documentation/current/method/eiffel-tutorial-et/et-other-mechanisms.wiki index 74422eca..26fd0457 100644 --- a/documentation/current/method/eiffel-tutorial-et/et-other-mechanisms.wiki +++ b/documentation/current/method/eiffel-tutorial-et/et-other-mechanisms.wiki @@ -138,8 +138,44 @@ The validity of a non-object call is restricted in ways that mirror these primar ==Convertibility== +{{underconstruction}} + It is useful at times to designate the instances of one type can be created through conversion of instance of some other type. This can be done through an Eiffel mechanism called '''convertibility'''. +{{Definition|Convertibility: converts to, converts from|
+
+A type U based on a class CU ''converts'' to a type T based on a class CT (and T ''converts from'' U) if either
+
+ CT has a ''conversion procedure'' using U as a conversion type, or
+
+ CU has a ''conversion query'' listing T as a conversion type,
+
+but not both.}} + +Before we get into an example of convertibility, let's list some of its underlying principles: +# Conversion Principle: No type may both ''conform'' and ''convert'' to another. +# Conversion Asymmetry Principle: No type may convert to another through both a ''conversion procedure'' and a ''conversion query''. +# Conversion Non-transitivity Principle: That V converts to U and U converts to T does not imply that V converts to T. + +Let's look at an example that may already be familiar to you. + + + my_string: STRING + my_system_string: SYSTEM_STRING + + … + + my_string := my_system_string + + +In the snippet above, we have attributes declared of type STRING and SYSTEM_STRING. + +We know that if we have a attribute of type STRING that we can make a direct assignment of a .Net type of string (that is, the .Net type System.String which we see as class SYSTEM_STRING) to our STRING attribute. + +We know also that SYSTEM_STRING does not conform to STRING, so according to the definition of compatibility, this must happen by conversion. + +It is possible because SYSTEM_STRING converts to STRING. + ==Tuple types==