Forget / Keep Mechanism

From EiffelStudio: an EiffelSoftware project
Revision as of 00:00, 20 February 2007 by Juliant (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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