Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #24644

Re: multiple inheritance in Java

From Sebastian <news@seyweiler.dyndns.org>
Newsgroups comp.lang.java.programmer
Subject Re: multiple inheritance in Java
Date 2013-07-05 08:04 +0200
Organization albasani.net
Message-ID <kr5nl5$s6u$1@news.albasani.net> (permalink)
References (2 earlier) <multiple-inheritence-20130702041514@ram.dialup.fu-berlin.de> <kqtjfn$uf0$1@dont-email.me> <multiple-inheritance-20130702120045@ram.dialup.fu-berlin.de> <kqufqd$52m$1@dont-email.me> <51d5ea42$0$302$14726298@news.sunsite.dk>

Show all headers | View raw


Am 04.07.2013 23:33, schrieb Arne Vajhøj:
[snip]
> I understand his »poor man's multiple inheritance«.
[snip]
>
> But it still has nothing to do with public field vs accessor
> as the above also be done as (and IMHO should be done as):
>
> public class A {
> public void a() { ... }
> }
>
> public class B {
> public void b() { ... }
> }
>
> public class C {
> private A a;
> private B b;
> public C() {
> a = new A();
> b = new B();
> }
> public A getA() {
> return a;
> }
> public B getB() {
> return b;
> }
> }
>
> C o = new C();
> o.getA().ma();
> o.getB().mb();
>
> Arne
Or even better, if you really want inheritance, use inner classes:

public class C {
     private CA a;
     private CB b;

     private class CA extends A {
         @Override
         public void a() { ... }
     }

     private class CB extends B {
         ...
     }

     public C() {
         a = new CA();
         b = new CB();
     }

     public A asA() {
         return a;
     }

     public B asB() {
         return b;
     }
}

-- Sebastian

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-01 21:52 -0400
  Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 00:09 -0400
    Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 08:13 -0400
      Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 17:33 -0400
        Re: multiple inheritance in Java Sebastian <news@seyweiler.dyndns.org> - 2013-07-05 08:04 +0200
    Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 13:17 -0400
      Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 13:40 -0400
        Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 14:29 -0400
          Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 15:12 -0400
            Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 17:23 -0400
              Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 17:25 -0400
          Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 15:44 -0400
            Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 16:28 -0400
              Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 16:44 -0400
              Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 17:13 -0400
                Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 22:12 -0400
  Re: multiple inheritance in Java Lew <lewbloch@gmail.com> - 2013-07-02 11:53 -0700
    Re: multiple inheritance in Java Steven Simpson <ss@domain.invalid> - 2013-07-03 10:46 +0100
      Re: multiple inheritance in Java lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-03 13:01 +0100
        Re: multiple inheritance in Java Steven Simpson <ss@domain.invalid> - 2013-07-03 14:12 +0100
          Re: multiple inheritance in Java lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-03 14:49 +0100
        Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-06 22:19 -0400
  Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 17:36 -0400
    Re: multiple inheritance in Java Gene Wirchenko <genew@telus.net> - 2013-07-05 11:01 -0700

csiph-web