getting round multiple inheritance

Discussion in 'Java' started by Colin Hemmings, Mar 11, 2006.

  1. Hi there I'm wondering if anyone can give me some advice. I have a
    program using RMI, and now I want to make some of the objects that are
    in it use observable. As java doesnt allow multiple inheritance, I can't
    use Observable as well as RMI.

    I've read that the best way round this is to create a new class which
    has the functionality of the Observable class, but I'm unsure exactly
    how to go about this, what to include in it, etc.

    could someone offer so advice on how i could go about sorting this?

    thanks
    Colin Hemmings, Mar 11, 2006
    #1
    1. Advertising

  2. Colin Hemmings

    Roedy Green Guest

    On Sat, 11 Mar 2006 18:42:39 GMT, Colin Hemmings
    <> wrote, quoted or indirectly quoted
    someone who said :

    >Hi there I'm wondering if anyone can give me some advice. I have a
    >program using RMI, and now I want to make some of the objects that are
    >in it use observable. As java doesnt allow multiple inheritance, I can't
    >use Observable as well as RMI.


    You object can have an Observable field. The only other way I know of
    solving that is to extend and Observable and implement the necessary
    additional inferfaces, perhaps with the facade design pattern.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Mar 11, 2006
    #2
    1. Advertising

  3. Colin Hemmings wrote:
    > Hi there I'm wondering if anyone can give me some advice. I have a
    > program using RMI, and now I want to make some of the objects that are
    > in it use observable. As java doesnt allow multiple inheritance, I can't
    > use Observable as well as RMI.
    >
    > I've read that the best way round this is to create a new class which
    > has the functionality of the Observable class, but I'm unsure exactly
    > how to go about this, what to include in it, etc.


    Ditch Observable. It never was a very good class.

    Presumably lots of JDK 1.0 code extended it. So Observable became part
    of that code's interface. That makes it difficult to deprecate.

    The all new Java 1.1 way is to use beans-style listeners.
    javax.swing.EventListenerList is useful to manage the listeners.
    javax.swing.ChangeListener is a rough equivalent to Observer. The only
    significant problem with these two types is that they are in the wrong
    package (they should have been in java.beans, or perhaps the java.util
    dumping ground).

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Mar 12, 2006
    #3
  4. Colin Hemmings wrote:
    > Hi there I'm wondering if anyone can give me some advice. I have a
    > program using RMI, and now I want to make some of the objects that are
    > in it use observable. As java doesnt allow multiple inheritance, I can't
    > use Observable as well as RMI.


    In Java you use interfaces as a sort of replacement for multiple
    inheritance. When designing an app your class hierarchy, the inheritance
    chain, would be focused on the most core functionality of your classes,
    while you would use interfaces for the extra features.

    F.ex lets say you are designing an 3D modeling program, then your
    classes core tasks would be about 3d concepts, while the non core
    functionality of the class would be covered by interfaces. So you could
    create a class hierarchy with a root class which inherits from RMI.

    E.g. RMI -> Shape -> Triangle
    Now triangle would perhaps implement the Observable interface so you
    could f.ex.check for collisions.

    > I've read that the best way round this is to create a new class which
    > has the functionality of the Observable class, but I'm unsure exactly
    > how to go about this, what to include in it, etc.


    I would use the Observable design pattern, not the class implementation
    available in the jdk. You can find a description of it on the net.
    Or you could read about it in the book "Head First Design Patterns",
    which is an excellent book for beginners about application design.

    /tom
    tom fredriksen, Mar 12, 2006
    #4
  5. Colin Hemmings

    Timo Stamm Guest

    tom fredriksen schrieb:
    > Colin Hemmings wrote:
    >> Hi there I'm wondering if anyone can give me some advice. I have a
    >> program using RMI, and now I want to make some of the objects that are
    >> in it use observable. As java doesnt allow multiple inheritance, I
    >> can't use Observable as well as RMI.

    >
    > In Java you use interfaces as a sort of replacement for multiple
    > inheritance.


    I think I understand what you mean, but I don't quite agree with your
    explanations:

    Inheritance is a powerful tool for reuse. Interfaces just seperate
    declarations from implementations. Interfaces can actually use multiple
    inheritance (interface X extends A, B), but I don't think that they can
    be seen as a /replacement/ for multiple inheritance, because the
    implementation is not inherited.

    It is possible to use something like multiple inheritance in java,
    though. You can use the composite pattern and delegation (like defined
    by the GoF). There is java.lang.Proxy, which already does most of the
    dirty work.

    But it doesn't solve all problems, and it is still much more verbose in
    java than in a language with built-in support for multiple inheritance.


    > When designing an app your class hierarchy, the inheritance
    > chain, would be focused on the most core functionality of your classes,
    > while you would use interfaces for the extra features.
    >
    > F.ex lets say you are designing an 3D modeling program, then your
    > classes core tasks would be about 3d concepts, while the non core
    > functionality of the class would be covered by interfaces. So you could
    > create a class hierarchy with a root class which inherits from RMI.


    Are we talking about Remote Method Invocation? Why should a 3D library
    have anything to to with RMI, let alone, extend its core classes from a
    RMI class?

    What if you need another technology than RMI in the next 3D app? You
    would either have to make radical changes to the library or rewrite it.


    Timo
    Timo Stamm, Mar 12, 2006
    #5
  6. Timo Stamm wrote:
    > tom fredriksen schrieb:
    >> Colin Hemmings wrote:
    >>> Hi there I'm wondering if anyone can give me some advice. I have a
    >>> program using RMI, and now I want to make some of the objects that
    >>> are in it use observable. As java doesnt allow multiple inheritance,
    >>> I can't use Observable as well as RMI.

    >>
    >> In Java you use interfaces as a sort of replacement for multiple
    >> inheritance.

    >
    > I think I understand what you mean, but I don't quite agree with your
    > explanations:
    > Inheritance is a powerful tool for reuse. Interfaces just seperate
    > declarations from implementations. Interfaces can actually use multiple
    > inheritance (interface X extends A, B), but I don't think that they can
    > be seen as a /replacement/ for multiple inheritance, because the
    > implementation is not inherited.


    I sort of technically agree with you. Its just a matter of point of view.


    > Are we talking about Remote Method Invocation? Why should a 3D library
    > have anything to to with RMI, let alone, extend its core classes from a
    > RMI class?
    >
    > What if you need another technology than RMI in the next 3D app? You
    > would either have to make radical changes to the library or rewrite it.


    It was just an example made up to fit the question, but not a very good
    one. The point was that you can for some things make it the root class
    of the hierarchy if it is needed by all subclasses, that way you can at
    least get one implementation in there for you hierarchy, a sort of half
    multiple inheritance method. (The last part is bollocks, its jsut my way
    of viewing it)
    tom fredriksen, Mar 12, 2006
    #6
    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. Replies:
    0
    Views:
    1,063
  2. Rouslan Korneychuk
    Replies:
    8
    Views:
    569
    Rouslan Korneychuk
    Feb 10, 2011
  3. JJ

    Multiple Round Trips

    JJ, Dec 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    128
  4. OliverMarchand

    Float.round - should it be round-to-even

    OliverMarchand, Apr 12, 2006, in forum: Ruby
    Replies:
    2
    Views:
    206
    OliverMarchand
    Apr 12, 2006
  5. cerr

    reading file round and round

    cerr, Mar 19, 2010, in forum: Perl Misc
    Replies:
    6
    Views:
    167
    Peter J. Holzer
    Mar 20, 2010
Loading...

Share This Page