Difference between revisions of "Replication"

(Basic cases of direct repeated inheritance)
(Basic cases of direct repeated inheritance)
Line 21: Line 21:
 
end
 
end
 
</code>
 
</code>
 +
====Three cases of non-conforming repeated inheritance====
 
Lets have look at D1 that repeatedly inherits from B:
 
Lets have look at D1 that repeatedly inherits from B:
 
<code>[eiffel, N]
 
<code>[eiffel, N]
Line 35: Line 36:
  
 
And an informal description of the semantics: An object of class D1 contains two physical attributes (f_1 and f_2). A call to feature g_1 results in f_1 being incremented and a call to g_2 increments f_2.
 
And an informal description of the semantics: An object of class D1 contains two physical attributes (f_1 and f_2). A call to feature g_1 results in f_1 being incremented and a call to g_2 increments f_2.
 +
 +
Lets do the same for D2:
 +
 +
<code>[eiffel, N]
 +
class
 +
  D2
 +
inherit {NONE}
 +
  B
 +
      rename g as g_1 end
 +
  B
 +
      rename g as g_2 end
 +
feature
 +
end   
 +
</code>
 +
 +
An object of class D2 contains one physical attribute (f). A call to either g_1 or g_2 results in f being incremented.
 +
 +
Class D3 should be rejected by the compiler:
 +
<code>[eiffel, N]
 +
class
 +
  D3
 +
inherit {NONE}
 +
  B
 +
      rename f as f_1 end
 +
  B
 +
      rename f as f_2 end
 +
feature
 +
end   
 +
</code>
 +
 +
Since an object of class D3 would have two physical attributes f_1 and f_2, it is not clear which one g should increment.

Revision as of 09:28, 25 August 2006


Work in progress!

We start with some very basic examples, for this we consider all the classes not to be inherited by ANY.

Example set

Basic cases of direct repeated inheritance

The following set of example will base on class B:

class
   B
feature
   f: INTEGER
   g
      do 
         f := f + 1 
      end
end

Three cases of non-conforming repeated inheritance

Lets have look at D1 that repeatedly inherits from B:

class
   D1
inherit {NONE}
   B
      rename f as f_1, g as g_1 end
   B
      rename f as f_2, g as g_2 end
feature
end

And an informal description of the semantics: An object of class D1 contains two physical attributes (f_1 and f_2). A call to feature g_1 results in f_1 being incremented and a call to g_2 increments f_2.

Lets do the same for D2:

class
   D2
inherit {NONE}
   B
      rename g as g_1 end
   B
      rename g as g_2 end
feature
end

An object of class D2 contains one physical attribute (f). A call to either g_1 or g_2 results in f being incremented.

Class D3 should be rejected by the compiler:

class
   D3
inherit {NONE}
   B
      rename f as f_1 end
   B
      rename f as f_2 end
feature
end

Since an object of class D3 would have two physical attributes f_1 and f_2, it is not clear which one g should increment.