From d9a1b20bad88e0a027cba89ac52632b914eef408 Mon Sep 17 00:00:00 2001 From: halw Date: Fri, 6 Apr 2012 16:23:19 +0000 Subject: [PATCH] Replaced explanation of assignment attempt with that of object test. Author:halw Date:2012-04-06T16:23:19.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1059 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../eiffel-net/inheritance.wiki | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/documentation/current/platform-specifics/microsoft-windows/net/eiffel-net-language/eiffel-net/inheritance.wiki b/documentation/current/platform-specifics/microsoft-windows/net/eiffel-net-language/eiffel-net/inheritance.wiki index 4f314bfe..744cab59 100644 --- a/documentation/current/platform-specifics/microsoft-windows/net/eiffel-net-language/eiffel-net/inheritance.wiki +++ b/documentation/current/platform-specifics/microsoft-windows/net/eiffel-net-language/eiffel-net/inheritance.wiki @@ -304,7 +304,7 @@ Static typing tells us at compile time that it is safe to apply perimeter< Dynamic binding tells us that when we apply perimeter, we know that the most appropriate version of the feature will get applied at runtime. -===Assignment Attempt=== +===Object Test=== Now let's add another situation. Consider the code below: @@ -324,31 +324,18 @@ But in the case above, the guarantee cannot be made. my_polygon is Does this mean that we can never do RECTANGLE things with this instance again, once we have attached it to my_polygon? -No. There is a language facility called the "assignment attempt" which will come to our rescue. The assignment attempt will allow us safely to attach our instance back to an entity typed as RECTANGLE. After doing so, we are free use RECTANGLE features. +No. There is a language facility called the '''object test''' which will come to our rescue. The object test will allow us safely to attach our instance back to an entity typed as RECTANGLE. After doing so, we are free use RECTANGLE features. my_polygon := my_rectangle print (my_polygon.perimeter) - another_rectangle ?= my_polygon - print (another_rectangle.width) - - -The assignment attempt uses the syntax "?=", versus the ":=" of assignment. - -This is significant ... as is the name assignment attempt. The reason is that it is possible in some context that my_polygon will be attached to something other than a rectangle when we do this: - - another_rectangle ?= my_polygon - - -If it were true that my_polygon were attached to an instance of say TRIANGLE when the assignment attempt above was executed, then another_rectangle would be left as a Void reference. As a consequence, it is prudent to check to see if the attachment has actually been made before trying to apply features. Applying a feature to a Void reference will cause an exception. Almost always, assignment attempt will be used in the following manner: - - my_polygon := my_rectangle - print (my_polygon.perimeter) - another_rectangle ?= my_polygon - if another_rectangle /= Void then -- Make sure assignment happened - print (another_rectangle.width) + if attached {RECTANGLE} my_polygon as l_rect then + print (l_rect.width) end - +In this code, the entity l_rect is a fresh local entity produced during the object test. So, the code can be read: if at this point, my_polygon is attached to an instance of type RECTANGLE, then attach that instance to a fresh local entity named l_rect, then apply {RECTANGLE}.width to l_rect and print the result. + + +:'''Note:''' The object test replaces the functionality of an obsolete mechanism called assignment attempt. Assignment attempt used the syntax '''?=''' in the context of assignment versus the ''':=''' of normal assignment.