Forget / Keep Mechanism

Revision as of 15:00, 19 February 2007 by Juliant (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

local
  a: ANIMAL
  c: CAT
do
    -- illegal assignment, ANIMAL and CAT don't conform
  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