Reputation
1,564
Top tag
Next privilege 2,000 Rep.
Edit questions and answers
Badges
9 14
Newest
 Yearling
Impact
~250k people reached

  • 0 posts edited
  • 0 helpful flags
  • 144 votes cast
Apr
28
comment If I implement an Interface, is it called an Inheritance?
Once you look at it that way, it's pretty clear that pre java-8 interfaces had nothing to do with the common usage of the term "Inheritance" (which is class inheritance). This is where most java programmers have an initial negative reaction to this answer... we're old-school and not used to these new-fangled functional constructs.
Apr
28
comment If I implement an Interface, is it called an Inheritance?
I've been thinking about what bothers me so much about the terminology around inheriting abstract interface methods into abstract classes and it's that we are using the unqualified word "Inheritance". It seems much cleaner if we clearly specify the two kinds of "Inheritance", interface and class. The two terms cross over slightly in that a class can inherit a default method from an interface using "class inheritance" and a class can inherit an abstract method requirement from an interface using "Interface Inheritance". (Those two exceptions being the answer to this question).
Apr
28
comment If I implement an Interface, is it called an Inheritance?
By the way, with the updates I think this is a fantastic answer.
Apr
28
comment If I implement an Interface, is it called an Inheritance?
@ian it would not be inheritance. Only default methods (because they have an implementation) are REALLY inherited (With the slight and strange exception of inheriting the requirement to implement an abstract method). In general I would just say be very careful saying interfaces use inheritance to anyone who might be evaluating your programming skills for any reason.. moreover be very specific if you choose to use that wording. An extremely valid and useful test question would be "Show me examples of inheritance" looking for someone to incorrectly mention interfaces.
Apr
28
comment If I implement an Interface, is it called an Inheritance?
With inheritance you would override a method. This is a key part, you change the way it works. With an interface you tend not to override (although default methods are an exception)--you tend to implement them. That said, what I really meant about the interview is if someone used the terminology inherits in relation to a class implementing an interface without mentioning these cases, they would certainly not understand the basic terminology and it's general usage in team communication.
Apr
28
comment If I implement an Interface, is it called an Inheritance?
@EricLippert It does inherit the abstract method. (If the interface has an abstract method, the abstract class will too). If your class IMPLEMENTS the method it's no longer inherited, it's implemented like with all the non-abstract class definitions. that's why I said it's not really the same concept as the class inheritance that the Original question was referring to. Class Inheritance as per the original question would, for example, absolutely not apply to the concept of implementing a java 7 interface in a concrete (non-abstract) class.
Apr
28
comment If I implement an Interface, is it called an Inheritance?
@EricLippert As I said it's used correctly in that quote but really only because of Default Methods If you were to say a class inherited from an interface, you'd only be referring to default methods--not normal method definitions. You'd never use the term with java 7 unless you were to say it "inherited" the responsibility to implement an abstract method which is really not the "Class Inheritance" concept we're discussing. If you were to say that a class implementing an abstract interface inherited it, you'd be straight out wrong (and that's not what the quote in this answer says).
Apr
27
comment If I implement an Interface, is it called an Inheritance?
I'm not convinced that quote even applies to general inheritance as the word is usually used in coding EXCEPT that it points up the one case where implementing an interface is truly inheriting--default methods. I would certainly not say I was inheriting from an interface except when it comes to default methods and possibly abstract methods (Since you are truly inheriting the responsibility to implement these methods). For normal method definitions though I'd really look askance at someone who used the word inherit over implement--I'd probably even consider them plain old wrong in an interview.
Dec
3
comment Is there any “real” reason multiple inheritance is hated?
@gbjbaanb You are right, it is easy for someone who hasn't been burnt to mess up any feature--in fact it's almost a requirement for learning a feature that you mess it up in order to see how to best use it. I'm kind of curious because you seem to be saying that not having MI forces more DI/IoC which I haven't seen--I wouldn't think that the consultant code you got with all the crappy interfaces/DI would have been better also having a whole crazy many-to-many inheritance tree, but it could be my inexperience with MI. Do you have a page I could read on replacing DI/IoC with MI?
Sep
14
awarded  Yearling
Jul
7
answered Do objects in OOP have to represent an entity?
Jul
7
comment Do objects in OOP have to represent an entity?
I've been programming OO too long I guess--when I looked at MyRepository I immediately pictured a glass bowl on my dresser with a bunch of coins and crap in it. Reach in and grab out a penny, or a button....
Mar
19
comment Static functions vs classes
Utilities without business logic often don't have a good OO solution and the best you can do is static classes and fixed classes like collections. If you really must do a general purpose utility you might as well abandon oo like collections, math util and all the other utilities do. In this case, he probably is just using one collection for his business code so why implement a general solution?
Mar
18
answered Static functions vs classes
Mar
18
answered Is it ok to break the “is a” relationship if I just want part of a class' functionality?
Jan
19
revised Does the use of debuggers have an effect on the efficiency of programmers?
added 44 characters in body
Jan
16
revised Is it always a best practice to write a function for anything that needs to repeat twice?
added 218 characters in body
Jan
15
answered Is it always a best practice to write a function for anything that needs to repeat twice?
Jan
12
awarded  Enlightened
Jan
12
awarded  Nice Answer