Difference between revisions of "Forget / Keep Mechanism"
| Line 47: | Line 47: | ||
Types which have covariant redefined features will not be conform. | Types which have covariant redefined features will not be conform. | ||
| + | |||
| + | {| class="wikitable" | ||
| + | |- | ||
| + | | what you write | ||
| + | | what is implied after you covariantly redefine <e>eat</e> | ||
| + | |- | ||
| + | | | ||
| + | <e> | ||
| + | class CAT | ||
| + | |||
| + | inherit | ||
| + | |||
| + | ANIMAL | ||
| + | redefine | ||
| + | eat | ||
| + | end | ||
| + | |||
| + | ... | ||
| + | </e> | ||
| + | | | ||
| + | <e> | ||
| + | class CAT | ||
| + | |||
| + | inherit | ||
| + | |||
| + | ANIMAL | ||
| + | forget | ||
| + | eat | ||
| + | redefine | ||
| + | eat | ||
| + | end | ||
| + | |||
| + | ... | ||
| + | </e> | ||
| + | |} | ||
| + | |||
| + | where <e>ANIMAL</e> does not conform to <e>ANIMAL forget all</e>: | ||
| + | |||
| + | <e> | ||
| + | local | ||
| + | normal_animal: ANIMAL | ||
| + | forget_animal: ANIMAL forget eat end | ||
| + | do | ||
| + | -- this assignment is legal | ||
| + | forget_animal := normal_animal | ||
| + | |||
| + | -- this assignment is illegal since the forget_animal lacks | ||
| + | -- the eat feature and thus cannot be used as an ANIMAL | ||
| + | normal_animal := forget_animal | ||
| + | end | ||
| + | </e> | ||
| + | |||
| + | Now the cat-call example: | ||
<e> | <e> | ||
| Line 54: | Line 107: | ||
do | do | ||
-- illegal assignment, ANIMAL and CAT don't conform | -- illegal assignment, ANIMAL and CAT don't conform | ||
| + | -- since CAT inherits from ANIMAL forget eat | ||
a := c | a := c | ||
a.eat (food) | a.eat (food) | ||
Revision as of 16:22, 19 February 2007
Warning: Warning: Article under development
Example
class ANIMAL feature eat (f: FOOD) end
class CAT inherit ANIMAL redefine eat end feature eat (f: CAT_FOOD) end
cat-call:
local a: ANIMAL c: CAT do a := c a.eat (food) end
forget-mechanism:
Types which have covariant redefined features will not be conform.
| what you write | what is implied after you covariantly redefine eat
|
class CAT inherit ANIMAL redefine eat end ... |
class CAT inherit ANIMAL forget eat redefine eat end ... |
where ANIMAL does not conform to ANIMAL forget all:
local normal_animal: ANIMAL forget_animal: ANIMAL forget eat end do -- this assignment is legal forget_animal := normal_animal -- this assignment is illegal since the forget_animal lacks -- the eat feature and thus cannot be used as an ANIMAL normal_animal := forget_animal end
Now the cat-call example:
local a: ANIMAL c: CAT do -- illegal assignment, ANIMAL and CAT don't conform -- since CAT inherits from ANIMAL forget eat a := c a.eat (food) end
local a: ANIMAL forget all end c: CAT do -- legal, CAT conforms to ANIMAL forget all a := c -- illegal, ANIMAL forget all doesn't have a feature eat a.eat (food) end

