Issues about delegation

"J. Baltasar García Perez-Schofield" jgarcia at
Wed Nov 5 11:06:31 UTC 2003

         Hi, there !

         I've some doubts about a language employing only delegation as its 
inheritance mechanism. Perhaps these doubts are simple and are answered 
elsewhere (probably in some self paper I should study), or perhaps I'm even 
missing something big.  Anyway, I would like to have some feedback about this.

         Suppose a system which includes a compiler for a protoype-based 
object-oriented language, with single inheritance, implemented through 
         Suppose you have a prototype such as this one (please let me use 
an [imperative, classic, C++/Java-like] pseudo-code):

         OBJ Person
                 ATR Parent Object
                 ATR Name ""
                 MTH getName
                 MTH putName

         So, therefore, the object Person derives from the root prototype 
object (called Object here), and has only one atributte (for the shake of 
simplicity), called "Name" which should store a String (i.e., a copy of the 
String prototype, which is the name of the person).

         If you want to create persons, then you just copy them. The system 
is in charge of copying their attributes (so, each person will have its own 
name, because the attributes (except "parent") are copied recursively). 
Here I suppose this is done by calling a "clone" method which is actually 
defined in "Object" (so the method look up runs throgh the "Parent" atributte).

         joe = Person.clone();
         mary = Person.clone();

         Console.write(joe.getName());           // Writes "Joe"
         Console.write(mary.getName());          // Writes "Mary"

         So far, so good. But I don't know how a language such as this one 
would cope with prototypes derived from "Person". For example:

         OBJ Employee
                 ATR Parent Person

         It it semantically correct - ane employee is a class of person -, 
and it would work employing a concatenation mechanism for inheritance.

         If you create two objects:

         joe2 = Employee.clone();
         mary2 = Employee.clone();


         Console.write(joe2.getName());          // Writes "MARY"
         Console.write(mary2.getName());         // Writes "MARY"

         These two objects, joe2, and mary2, share the shame String, 
because both objects have a "parent" attribute pointing to Person. Worst of 
all, joe2 and mary2 are actually modifying a prototype (an object which is 
playing the role, in this case, of a class).

         How can I solve this ?
         Of course I can think of some work arounds, such as recreating the 
"name" atribute in Employee, or using a composition relation instead of the 
inheritance one, but I think this should be possible to be solved whithin 

         Thank you in advance,


PBC - J. Baltasar García Perez-Schofield
Dep. Informática, Universidad de Vigo, España (Spain)

More information about the Self-interest mailing list