Implementing inheritance in JAVA

Discussion in 'Java' started by manjunath.d@gmail.com, Feb 8, 2005.

  1. Guest

    Hi,

    I am a naive JAVA user. Can you please tell me, oh how to implement
    the following scenario

    A
    ^ ^
    / \
    B C
    ^ ^
    \ /
    D

    Classes B and C extends class A, but how to define class D, such that
    members of both B and C are available to D.

    Thanks
    >> manjunath
     
    , Feb 8, 2005
    #1
    1. Advertising

  2. wrote in comp.lang.java.programmer:
    > Classes B and C extends class A, but how to define class D, such that
    > members of both B and C are available to D.


    Java does not support multiple inheritance, so class D can not
    provide the methods through Java's inheritance mechanism.

    Internet contains a lot of information about this. Search Google
    for "java multiple inheritance".

    --
    Antti S. Brax Rullalautailu pitää lapset poissa ladulta
    http://www.iki.fi/asb/ http://www.cs.helsinki.fi/u/abrax/hlb/
    "Disconnect this cable to shorten, re-connect to lengthen."
    -- Instructions on Logitech's USB mouse extension cord.
     
    Antti S. Brax, Feb 8, 2005
    #2
    1. Advertising

  3. John Guest

    wrote:
    > Hi,
    >
    > I am a naive JAVA user. Can you please tell me, oh how to implement
    > the following scenario
    >
    > A
    > ^ ^
    > / \
    > B C
    > ^ ^
    > \ /
    > D
    >
    > Classes B and C extends class A, but how to define class D, such that
    > members of both B and C are available to D.
    >
    > Thanks
    >
    >>>manjunath

    >
    >


    You can't. Make D a subclass of A, just like B and C. If you want to
    specify some additional behaviour for D then define interface(s) that it
    must implement, along with (optionally) either B, C, or both B and C.

    John
     
    John, Feb 8, 2005
    #3
  4. You cannot do that. Java does not support multiply inheritence of
    *implementation*.

    However, if you were to make A, B and C _interfaces_, then D could
    implement both B and C. Then, using patterns (such as
    Wrapper/Decorator), you could do the following:

    A--extended by-->B--implemented by-->Bimpl
    A--extended by-->C--implemented by-->Cimpl

    D--extends both-->[B,C]--contains instances of-->[Bimpl,Cimpl]

    Then your D could pass calls to those methods defined in the A, B and C
    interfaces to the specific instance variables of tyep Bimpl and Cimpl
    as necessary.
     
    Darryl L. Pierce, Feb 8, 2005
    #4
  5. Darryl L. Pierce wrote:
    > You cannot do that. Java does not support multiply inheritence of
    > *implementation*.
    >
    > However, if you were to make A, B and C _interfaces_, then D could
    > implement both B and C. Then, using patterns (such as
    > Wrapper/Decorator), you could do the following:
    >
    > A--extended by-->B--implemented by-->Bimpl
    > A--extended by-->C--implemented by-->Cimpl
    >
    > D--extends both-->[B,C]--contains instances of-->[Bimpl,Cimpl]
    >
    > Then your D could pass calls to those methods defined in the A, B and C
    > interfaces to the specific instance variables of tyep Bimpl and Cimpl
    > as necessary.
    >


    In our paper

    On Multiple Inheritance in Java
    L. Bettini, M. Loreti, B. Venneri. Technology of Object-Oriented
    Languages, Systems and Architectures, Proc. of TOOLS Eastern Europe
    2002, (Theo D'Hondt, Ed.), pages 1-15, Kluwer Academic Publishers, 2003.
    http://music.dsi.unifi.it/abstracts/multipinh-abs.html
    http://music.dsi.unifi.it/papers/multipinh.ps.gz

    we provide a general algorithm to automatically implement multiple
    inheritance in Java; this also shows that it is not straighforward to
    simulate the exact semantics of multiple inheritance through interfaces
    and object composition.

    Lorenzo

    --
    +-----------------------------------------------------+
    | Lorenzo Bettini ICQ# lbetto, 16080134 |
    | PhD in Computer Science |
    | Dip. Sistemi e Informatica, Univ. di Firenze |
    | Tel +39 055 4237441, Fax +39 055 4237437 |
    | Florence - Italy (GNU/Linux User # 158233) |
    | Home Page : http://www.lorenzobettini.it |
    | http://music.dsi.unifi.it XKlaim language |
    | http://www.lorenzobettini.it/purple Cover Band |
    | http://www.gnu.org/software/src-highlite |
    | http://www.gnu.org/software/gengetopt |
    | http://www.lorenzobettini.it/software/gengen |
    | http://www.lorenzobettini.it/software/doublecpp |
    +-----------------------------------------------------+
     
    Lorenzo Bettini, Feb 14, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,148
    Martijn van Steenbergen
    Dec 21, 2003
  2. cppsks
    Replies:
    0
    Views:
    827
    cppsks
    Oct 27, 2004
  3. karthikbalaguru
    Replies:
    9
    Views:
    1,041
  4. Jaco Naude
    Replies:
    5
    Views:
    573
    Jaco Naude
    Apr 1, 2009
  5. bintom
    Replies:
    5
    Views:
    274
    bintom
    Mar 21, 2011
Loading...

Share This Page