7 ms·
Actually I think a bigger problem is that Java programmers (not C++) create hundreds of interfaces. Thus Java becomes an artifact hell (EJB 2.0 was a nightmare)
by agentgt 15y ago
Actually I think a bigger problem is that Java programmers (not C++) create hundreds of interfaces. Thus Java becomes an artifact hell (EJB 2.0 was a nightmare).
Abstract classes on the other hand are very useful but most Java programmers think... "well what if in the future I need...".
If Java just had traits/mixins, closures, literals, and some syntax brevity it would be a pretty damn descent language... oh wait that's Scala.
- ebiester 15y agoNo, that's Groovy. Scala is the equivalent of C++ - trying to be everything to everyone and creating an expansive behemoth that everyone picks their own subset from.
- soc88 15y agoSounds like you never actually used it.
- sreque 15y agoA dynamic language that is 100-1000x slower (http://stronglytypedblog.blogspot.com/2009/07/java-vs-scala-vs-groovy-performance.html http://stronglytypedblog.blogspot.com/2009/07/java-vs-scala-...) does not equal Java plus closures and a few other syntactic niceties. You would have been much more accurate referencing Xtend, Kotlin, Gosu, or Ceylon.
- timclark 15y agoYou don't have to create an interface! One of my favourite interview questions is why do you use interfaces in Java? The majority of people I interviewed said that it a good design used interfaces and had nothing more to say. In code review if you have an interface and only one implementation I'd make you remove the interface - I call this the unnecessary Impl pattern since the class is traditionally called NameOfInterfaceImpl. Also you don't have to name property accessors getX() and setX() if you don't want to.
- neeleshs 15y agoInterfaces are a (or used to be ) huge help with unit tests with mocking etc. With better class mocking libraries now, that advantage has diminished.
- VladRussian 15y ago> In code review if you have an interface and only one implementation I'd make you remove the interface which changes the contract from "this component will accept and work with anything implementing this interface" to "this component will accept and work with anything of this class or inheriting from this class". And without multiple inheritance ... Do you feel the difference?
- reddiric 15y agoIf there is only one implementation of an Interface, "anything implementing this Interface" and "anything of this class" are the same thing. Coding to an interface is a good thing - but it's the concept "interface", not necessarily the language feature named "Interface" that's important. If/when you have multiple concrete objects which share the same interface, it's trivial there to switch references from the concrete type to that of the Interface (you were coding to a conceptual interface representing a consistent abstraction of a single responsibility in the beginning so your Interface is interchangeable, correct?)
- VladRussian 15y ago> If/when you have multiple concrete objects which share the same interface, it's trivial there to switch references from the concrete type to that of the Interface you're a lucky person that it has been trivial for you, your teammates and all the known and unknown clients of your code and components. I can only envy your experience.
- timclark 15y agoLots of Java development is carried out for internal business applications and like it or not they would typically be integrated with third parties using something like SOAP or a shared database. So in this type of application the choice of a concrete class over an interface probably has little impact on the known or unknown clients of your code. However, as you point out, if you are presenting a Java API to your known and unknown clients you had better think carefully about which abstractions you are going to expose and interfaces are probably going to be very helpful.
- tikhonj 15y agoScala is a very different beast from Java. It has all that you mentioned, to be sure, but it also has a lot more. You should check out Gosu[1], which is a language that does exactly what you say without adding complexity or being as different from Java as Scala. [1]: http://gosu-lang.org http://gosu-lang.org
- spullara 15y agoActually, that is probably a future version of Java. JDK 8 will have closures and something very much like mixins.