Difference between revisions of "Forget / Keep Mechanism"

(syntax)
Line 178: Line 178:
  
 
<e>
 
<e>
    -- normal declaration is an object with all features and does
+
  -- normal declaration is an object with all features and does
    -- not conform to subtypes which have covariantly redefined features
+
  -- not conform to subtypes which have covariantly redefined features
  a1: ANIMAL
+
a1: ANIMAL
  
    -- a type marked as `poly' will loose all covarianlty redefined features
+
  -- a type marked as `poly' will loose all covarianlty redefined features
    -- and be conform to all subtypes
+
  -- and be conform to all subtypes
  a2: poly ANIMAL
+
a2: poly ANIMAL
  
    -- a type which only forgets the features `eat' and `drink' but not other
+
  -- a type which only forgets the features `eat' and `drink' but not other
    -- covarianlty redefined features
+
  -- covarianlty redefined features
  a3: ANIMAL forget eat, drink end
+
a3: ANIMAL forget eat, drink end
  
    -- a type which forgets all covariantly redefined features. equivalent to `poly'
+
  -- a type which forgets all covariantly redefined features. equivalent to `poly'
  a4: ANIMAL forget all end
+
a4: ANIMAL forget all end
 
</e>
 
</e>
  
Line 197: Line 197:
  
 
<e>
 
<e>
    -- normal declaration is an object which forgets all covariantly
+
  -- normal declaration is an object which forgets all covariantly
    -- redefined features and is conform to all subtypes
+
  -- redefined features and is conform to all subtypes
  b1: ANIMAL
+
b1: ANIMAL
  
    -- a type which keeps all features and looses conformance to subtypes which
+
  -- a type which keeps all features and looses conformance to subtypes which
    -- covariantly redefine features
+
  -- covariantly redefine features
  b2: mono ANIMAL
+
b2: mono ANIMAL
  
    -- a type which conforms to all subtypes except those who covariantly redefine
+
  -- a type which conforms to all subtypes except those who covariantly redefine
    -- feature `eat'
+
  -- feature `eat'
  b3: ANIMAL keep eat end
+
b3: ANIMAL keep eat end
  
    -- a type which keeps all features. equivalent to `mono'
+
  -- a type which keeps all features. equivalent to `mono'
  b4: ANIMAL keep all end
+
b4: ANIMAL keep all end
 
</e>
 
</e>

Revision as of 17:06, 19 February 2007

Warning.png Warning: Warning: Article under development

covariant feature redefinition

Example

class ANIMAL
 
feature
 
  eat (f: FOOD)
 
end
class CAT
 
inherit
 
  ANIMAL
    redefine
      eat
    end
 
feature
 
  eat (f: CAT_FOOD)
 
end
class FOOD
end
 
class CAT_FOOD
 
inherit
 
  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. A feature which is covariantly redefined changes its inherit clause implicitly to inherit from a parent class which has the redefined feature in a forget clause.

what you write what is implied
class CAT
 
inherit
 
  ANIMAL
    redefine
      eat
    end
 
feature
 
  eat (f: CAT_FOOD)
 
end
class CAT
 
inherit
 
  ANIMAL
    forget 
      eat
    redefine
      eat
    end
 
feature
 
  eat (f: CAT_FOOD)
 
end

The conformance between ANIMAL and ANIMAL forget eat and ANIMAL forget all is as follows:

local
  normal_animal: ANIMAL
  forget_eat_animal: ANIMAL forget eat end
  forget_all_animal: ANIMAL forget all end
do
    -- this assignment is legal since all features present in the
    -- forget types are also present in the normal type
  forget_eat_animal := normal_animal
  forget_all_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_eat_animal
  normal_animal := forget_all_animal
 
    -- this assignment is legal since the forget all type
    -- has fewer or equal features than the forget eat type
  forget_all_animal := forget_eat_animal
 
    -- this assignment is only legal if only the feature `eat'
    -- is covariantly redefined in the type ANIMAL and thus
    -- forget eat is equivalent to forget all
  forget_eat_animal := forget_all_animal
 
end

Now the cat-call example with the new forget types:

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

generics

...


syntax

The first variant has the default on NOT forgetting features, thus breaking conformance between the type and its subclasses which use covariant redefinition.

-- normal declaration is an object with all features and does
  -- not conform to subtypes which have covariantly redefined features
a1: ANIMAL
 
  -- a type marked as `poly' will loose all covarianlty redefined features
  -- and be conform to all subtypes
a2: poly ANIMAL
 
  -- a type which only forgets the features `eat' and `drink' but not other
  -- covarianlty redefined features
a3: ANIMAL forget eat, drink end
 
  -- a type which forgets all covariantly redefined features. equivalent to `poly'
a4: ANIMAL forget all end

The second variant has the default on forgetting all features which are covariantly redefined, thus keeping conformance with subtypes.

-- normal declaration is an object which forgets all covariantly
  -- redefined features and is conform to all subtypes
b1: ANIMAL
 
  -- a type which keeps all features and looses conformance to subtypes which
  -- covariantly redefine features
b2: mono ANIMAL
 
  -- a type which conforms to all subtypes except those who covariantly redefine
  -- feature `eat'
b3: ANIMAL keep eat end
 
  -- a type which keeps all features. equivalent to `mono'
b4: ANIMAL keep all end