From 83543b0afc01b2d54610f9cfbe192a92d7af86b7 Mon Sep 17 00:00:00 2001 From: halw Date: Thu, 14 Jan 2010 17:09:43 +0000 Subject: [PATCH] Added non-conforming inheritance section Author:halw Date:2010-01-14T17:09:43.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@394 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../eiffel-tutorial-et/et-inheritance.wiki | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/documentation/current/method/eiffel-tutorial-et/et-inheritance.wiki b/documentation/current/method/eiffel-tutorial-et/et-inheritance.wiki index 0d27e10e..c4ec5961 100644 --- a/documentation/current/method/eiffel-tutorial-et/et-inheritance.wiki +++ b/documentation/current/method/eiffel-tutorial-et/et-inheritance.wiki @@ -879,6 +879,31 @@ Likewise the compiler in EiffelStudio will produce warnings in cases in which ca +===Non-conforming inheritance=== + +So far, our experience with inheritance is that of "conforming" inheritance ... the most commonly used type of inheritance. Conforming inheritance is what allows a direct instance (in the '''catcall''' example above) of COW to be attached at runtime to an entity of type ANIMAL. This can be a powerful modeling capability, but it is this same polymorphism facilitated by conforming inheritance that puts us in the danger of using polymorphic '''catcalls'''. + +In cases in which polymorphic attachment is not anticipated, the possibility of catcalls can be avoided by using '''non-conforming inheritance'''. Non-conforming inheritance is just a more restrictive form of inheritance. It allows features to be inherited from parent to heir, but it disallows polymorphic attachment of a direct instance of an heir to an entity based on a non-conforming parent. + +In order to use non-conforming inheritance for a particular parent, we use the marker {NONE} in the appropriate inheritance part of the class: + + +class + MY_HEIR_CLASS +inherit + MY_CONFORMING_PARENT +inherit + {NONE} MY_NON_CONFORMING_PARENT + ... + + +Here there are two inherit clauses, one to specify conforming parents, and one to specify non-conforming parents. The clause specifying the conforming inheritance must precede the one specifying the non-conforming inheritance. + +So, in this case, at runtime it is valid for a direct instance of MY_HEIR_CLASS to be attached to an entity of type MY_CONFORMING_PARENT, but not to an entity of type MY_NON_CONFORMING_PARENT. Accordingly, the compiler would reject any code in which an instance of MY_HEIR_CLASS could become attached to an entity of type MY_NON_CONFORMING_PARENT. Because the polymorphic attachment cannot be made, the possibility of a catcall is avoided. + + + +