Multiple Inheritance and Twin classes 
Author Message
 Multiple Inheritance and Twin classes

After discussing the Oberon programming language and twin
classes (Section 8.6 -  Mossenbock, H., Object-Oriented
Programming in Oberon-2, Springer-Verlag, 1993) in my
Programming Languages class, a few observations were
noted.  The following is a brief critique of the
limitations of twin classes.

One of the first observations that was brought up in
lecture was that the use of twin classes discourage further
inheritance from twin classes.  If the twin class concept
is used, any class that inherites from a twin class must
provide duplicate implementations for the two resulting
classes.

My instructor (Dr. Edgar Knapp) also noted twin classes
require the use of message records instead of methods.
Since twin classes do not allow sharing of the same methods
one needs to use message records to activate the appropriate
method in a twin class.  Also, sending messages is required
in order to keep both classes that make up the twin class
in a consistent state.

My own observation was that it is not possible to have a
simple and straight forward implementation of a twin class.
This is as a result of the problem that occurs when a
message is received by a twin class but is not recognized by
the twin class.  When one of the classes receives a message
that it does not recognize, it passes the message to its twin
class.  When the twin class does not recognize the message,
it passes the message back its twin class.  Thus the message
can end up being passed between the two classes infinitely.

Harold Brown
Graduate Student in Computer Science
Purdue University

PS: Could someone send me Dr. Mossenbock's email address.
    I would like to get his response on these points.



Mon, 20 May 1996 06:21:57 GMT  
 Multiple Inheritance and Twin classes
For those of us without PIO2, would you explain the concept of
"twin classes"?  Thanks.

--
A designer knows he has arrived at perfection not when there
is no longer anything to add, but when there is no longer
anything to take away.
                                -- Antoine de Saint-Exupery



Wed, 22 May 1996 13:47:49 GMT  
 Multiple Inheritance and Twin classes
: For those of us without PIO2, would you explain the concept of
: "twin classes"?  Thanks.

Templ also covers Twin Objects/Classes in a paper entitled :
A systematic approach to multiple inheritence implementation.
ACM SIGPLAN Vol 28. No. 4 April 1993.

Twin objects is the name of a technique to express the effect of
multiple inheritence using single inheritence. The idea is to
represent instances of a class that inherits from two classes
by a pair of two closely related objects - twins - that are always
generated together.

For C inheriting from both A and B we have :

        A = POINTER TO ADesc;
        ADesc = RECORD END;

        B = POINTER TO BDesc;
        BDesc = RECORD END;

        C = POINTER TO CDesc;
        CDesc = RECORD ( ADesc, BDesc ) END; (* multiple-inheritence *)

where the definition of C is just synatic suger for
the implementation of cross-linked twin classes CA and CB.

        CA = POINTER TO CADesc;
        CB = POINTER TO CBDesc;
        CADesc = RECORD ( ADesc )
                cb : CB;
        END;
        CBDesc = RECORD ( BDesc )
                ca : CA;
        END;

New objects are allocated as pairs :
 NEW( ca ); NEW( cb ); ca.b := cb; cb.a := ca;

Messaging is through type-bound procedure calls to
the appropriate twin.

Whitney



Mon, 27 May 1996 13:19:34 GMT  
 Multiple Inheritance and Twin classes

[..]
 ->  CA = POINTER TO CADesc;
 ->  CB = POINTER TO CBDesc;
 ->  CADesc = RECORD ( ADesc )
 ->          cb : CB;
 ->  END;
 ->  CBDesc = RECORD ( BDesc )
 ->          ca : CA;
 ->  END;
 ->
 -> New objects are allocated as pairs :
 ->  NEW( ca ); NEW( cb ); ca.b := cb; cb.a := ca;
 ->
 -> Messaging is through type-bound procedure calls to
 -> the appropriate twin.

This is possible, but not the "intended" way. To quote Moessenboeck:

 "CA objects handle A messages and forward B messages to their field b.
  CB objects do exactly the opposite."

Message here are synonymous with message records (otherwise,
extensibility goes out the window, requiring a change in both twins
every time a method is added).  Type-bound procedures are also called
methods (in this context).

Most of the problems that were mentioned at the start of this
thread can indeed be avoided by using type-bound methods instead of
message records, but this appears to create more problems than it
solves.

In short, I think twin classes are a hack, a poor man's substitute for
multiple inheritance.

Edgar Knapp

--

Purdue University                   (get PGP public key via finger)
Department of Computer Sciences     +1 (317) 494-6028 (voice)
West Lafayette, IN 47907-1398       +1 (317) 494-0739  (fax)



Tue, 28 May 1996 02:37:29 GMT  
 Multiple Inheritance and Twin classes

Quote:
> In short, I think twin classes are a hack, a poor man's substitute for
> multiple inheritance.

> Edgar Knapp

Seen more technically, twin classes are exactly the same
as multiple inheritance. In fact twin classes can be used
to derive a very efficient solution for multiple inheritance
when supported by a compiler. The derived solution is even
more efficient (believe it or not) than all C++ implementations
I know of. To speak in terms of E. Gamma and R. Johnson
(OOPSLA 93?) twin classes are an OO "design pattern" which
occurs in real applications but not very often. As far as I know,
twins are the only pattern which can profit from multiple
inheritance support in a language. The question remains
whether this special and rare case justifies the
complication of a language given the fact that it can be
expressed (in a poor man's solution) with single inheritance.

- Josef Templ, ETH Zurich



Wed, 29 May 1996 21:07:57 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Multiple Inheritance and Dynamic Class Structures

2. Multiple inheritance of generic classes

3. Multiple inheritance with meta classes?

4. Multiple Class Inheritance Question

5. Multiple Inheritance and Dynamic Class Structures

6. Different kind of inheritance/Multiple Inheritance

7. Multiple Dispatch (was Re: Replacing Multiple Inheritance with Java's Interfaces)

8. Classes - instance/class, methods/members, inheritance and best p ractices

9. Classes - instance/class, methods/members, inheritance and be st practices

10. Smalltalk and Multiple Inheritance

11. Free Multiple Inheritance for VisualWorks 2.0

12. Multiple inheritance

 

 
Powered by phpBB® Forum Software