Forget / Keep Mechanism

Revision as of 16:22, 19 February 2007 by Juliant (Talk | contribs)

Warning.png 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