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


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

Re: Object orientation question

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Object orientation question
Date Mon, 27 Oct 2014 23:51:30 +0100
Lines 49
Message-ID <cb80jkFmoa9U1@mid.individual.net> (permalink)
References <0b94f856-9631-48ee-8d2d-94055d79cfd6@googlegroups.com> <m2mb82$cef$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net QE5yQGlLYJwogl5f9IQD0A65ilrrQb2suPa4Eqr8buIiD0QX4=
Cancel-Lock sha1:03n8uNSgQqKRKs5trnTp059SgCE=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
In-Reply-To <m2mb82$cef$1@dont-email.me>
Xref csiph.com comp.lang.java.programmer:30217

Show key headers only | View raw


On 27.10.2014 21:51, Eric Sosman wrote:

 >      Clearly, the generated code is the same: AdditionInterface extends
 > BaseInterface, therefore any class implementing AdditionInterface also
 > necessarily implements BaseInterface.  If the class fails to provide a
 > method specified by BaseInterface, the code won't compile.  So the
 > question is purely about readability and style.

This is not fully correct: if you check with reflection you will see 
that there is a difference in what Class.getInterfaces() returns.

   public static void main(String[] args) {
     for (final Class<?> cl : Arrays.asList(Single.class, Both.class)) {
       System.out.println("Class name: " + cl.getName());

       for (final Class<?> ifac : cl.getInterfaces()) {
         System.out.println("  " + ifac.getName());
       }
     }
   }

yields in my test case

Class name: iface.inherit.Single
   iface.inherit.DerivedI
Class name: iface.inherit.Both
   iface.inherit.BaseI
   iface.inherit.DerivedI


>      Unless there's something rather unusual going on, I'd tend to favor
> brevity: Just say `class AdditionImpl implements AdditionInterface' and
> let it go at that.  Anyone who's curious about exactly what classes are
> extended and which interfaces are implemented can always consult the
> Javadoc, where it's all spelled out in gory detail.

I'm all with you on the readability through brevity here.  There is one 
more thing: by making AdditionInterface inherit BaseInterface the author 
clearly stated the intend that anything which implements 
AdditionInterface *is a* (or comprises) BaseInterface.  There is no need 
to express that again.  Since that inheritance is not likely to go away 
(such an interface change potentially affects a lot code and should thus 
not be done easily) there is no need to care for the case that the 
"extends" clause goes away leaving @Override dangling in AdditionImpl.

Kind regards

	robert

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


Thread

Object orientation question mike <mikaelpetterson@hotmail.com> - 2014-10-27 13:26 -0700
  Re: Object orientation question Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-10-27 16:51 -0400
    Re: Object orientation question Robert Klemme <shortcutter@googlemail.com> - 2014-10-27 23:51 +0100
      Re: Object orientation question Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-10-28 09:45 +0000
        Re: Object orientation question Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-10-28 08:29 -0400
          Re: Object orientation question Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-10-28 08:33 -0400
            Re: Object orientation question Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-10-28 16:26 +0000
        Re: Object orientation question Robert Klemme <shortcutter@googlemail.com> - 2014-10-29 08:35 +0100
          Re: Object orientation question Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-10-30 00:32 +0000

csiph-web