Results 1 to 8 of 8
  1. #1
    ajetrumpet is offline Member
    Join Date
    Feb 2013
    Posts
    57
    Rep Power
    0

    Default extends vs. implements

    all,

    Can someone give me their *common sense* interpretation of this please? the docs give an example of EXTENDS, and uses the bicycle vs. the mountain bike example. Is there any other way someone can explain this to me? I get it, but I want to hear other explanations of this just so I can get a better handle on the professionalism of other people that are seeing these posts.

    can you guys provide that? How is it that you think of this?

    thanks!

    the API: Inheritance (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: extends vs. implements

    You can both extend and implement a design. Doing so produces a modified design from a given one. Extending and implementing has to do with designs and not with the actual production of anything which is another question entirely.

    Some designs are quite abstract - they omit the details of what goes into a thing either completely or in part, but they do specify the behaviour the things will have (when an instance is later produced). Such designs can be implemented in the sense that another design can be drawn up which fills in the details. An implementation will say what sorts of components will be used, and how the required behaviour will be produced using those parts. Typically an implementation will include some behaviour that was not mentioned in the original, abstract, design but which is required by the specific implementation.

    Other designs are quite concrete in the sense that every detail is spelt out fully: every component, and how those components will interact to produce behaviour. But that's not the end of the line because even concrete designs can be extended. That is to say a new design can be made that adds some more functionality and, possibly, new parts that are used for the new functionality. The new design will have and do everything the old one had and did and, in that sense, it is said to extend the old one. The extended design will be "backwards compatible" because it doesn't remove any features.

    Abstract designs can be extended as well. New behaviour is added but, this time, without the details about how the new features will be implemented. Like extending concrete designs, extending abstract ones removes nothing and, so, does not break backwards compatibility.

    Concrete designs cannot, of course, be implemented because they already specify their parts and behaviour.

  3. #3
    ajetrumpet is offline Member
    Join Date
    Feb 2013
    Posts
    57
    Rep Power
    0

    Default Re: extends vs. implements

    pb,

    Sorry but that's kind of more academic than what I was seeking. So for instance, if you think in terms of "things", the word "extends" means nothing more than a class than a class that is "a type of" another class. This is not complicated at all, it's just a form of inheritance. So since that is a simplified version of the truth regarding "extends", what would be the equivalent explanation of the word "implements"?

    I hope that makes sense!

    thanks!

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: extends vs. implements

    So for instance, if you think in terms of "things", the word "extends" means nothing more than a class than a class that is "a type of" another class. This is not complicated at all, it's just a form of inheritance.
    "implements" also means "is a type of" and is a form of inheritance. So I would question the "means nothing more than" and "it's just a form of". They represent different ways of being a type of, and different ways of inheriting.

    I'm all in favour of simplicity. But Einstein's razor motivated both my observation that the distinction (at least in Java) relates to designs (aka types) and not the instances of which they are designs, and the introduction of the distinction between abstract and concrete designs.

    Hopefully others will have a go at describing the difference.

  5. #5
    ajetrumpet is offline Member
    Join Date
    Feb 2013
    Posts
    57
    Rep Power
    0

    Default Re: extends vs. implements

    Quote Originally Posted by pbrockway2 View Post
    "implements" also means "is a type of" and is a form of inheritance. So I would question the "means nothing more than" and "it's just a form of". They represent different ways of being a type of, and different ways of inheriting.
    I look at "extends", in terms of general usage, as a ways of describing an object that is "part of" a bigger object or concept. here are some examples I think can of:

    => yacht extends boat (yacht is a type of boat).
    => reservoir extends lake (reservoir is a type of lake).
    => skyscraper extends building (skyscraper is a type of building).

    all of these examples can be thought of, and compared to, numerous other software concepts. one such example would be the inheritance of properties from an object and building on those properties to include new properties when an object is an extension of a base object.

    do you agree?

    thanks!

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: extends vs. implements

    I don't agree, pretty much for the reasons I've given.

    First all three examples would serve equally well as examples of implementation rather than extension if yacht, boat, reservoir, lake etc were abstract. So they don't really illuminate the difference between the two ways of being a type of. And secondly, because - in Java at least - "the inheritance of properties from an object" doesn't exist as it does, eg, in JavaScript. Rather, inheritance (both varieties) is a relationship between types or designs of object not a relationship between objects.

    I'll frankly admit that #2 is wordy. (and deliberately does not attempt to relate the concepts of inheritance and implementation to Java's syntax) But it's what I think, as clearly as I can express it consistent with being precise.

  7. #7
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    256
    Rep Power
    3

    Default Re: extends vs. implements

    Basically at uni we are initially taught:

    Extends - enforces the "is-a" relationship
    implements - is a "contract" that an object has to abide to. So you could have car Class that implements CarReq (an interface) that enforces what method(s) the Car class must have.

  8. #8
    ajetrumpet is offline Member
    Join Date
    Feb 2013
    Posts
    57
    Rep Power
    0

    Default Re: extends vs. implements

    Quote Originally Posted by monkeyjr97 View Post
    Basically at uni we are initially taught:

    Extends - enforces the "is-a" relationship
    implements - is a "contract" that an object has to abide to. So you could have car Class that implements CarReq (an interface) that enforces what method(s) the Car class must have.
    I understand this *completely*. That is exactly right. Many ways to say the same thing. But this is just the *rules* of how some parts of Java work. In order to turn that into a workable product in the private sector is a completely different story. This is what I'm trying to get at here (in terms of how to think about it in my own mind).

    Quote Originally Posted by pbrockway2 View Post
    First all three examples would serve equally well as examples of implementation rather than extension if yacht, boat, reservoir, lake etc were abstract. So they don't really illuminate the difference between the two ways of being a type of. And secondly, because - in Java at least - "the inheritance of properties from an object" doesn't exist as it does, eg, in JavaScript. Rather, inheritance (both varieties) is a relationship between types or designs of object not a relationship between objects.
    it is so funny that you say things like this. pb, do you see what the difference is between you and I here? The difference mainly is that I'm trying to take what we both know (but you being able to express it in terms of a developer's "professionalism" and me being able to just "get it" without using specific terms to describe concepts) and keep it to myself in a way that I can explain how things work to almost anyone I run into. But in order to do that, I need to be able to take what other people say and just know what they are talking about. If you had the knowledge that I had, you would probably realize how easy all of this is. It's quite remarkable! You're not a shallow minded person pb, as I can tell, but this kind of frustration about how to create relevant product out of all of this knowledge *completely* stems from the fact that most software developers (who are just general employees, really) have shallow mindsets and can't see past their own responsibilities.

    But that's a problem in any walk of life. Working in technology only compounds the problem. See what I'm getting at? But regardless, I really appreciate your feedback here! It's incredibly helpful!

Similar Threads

  1. Replies: 4
    Last Post: 01-17-2012, 01:39 AM
  2. What about variables? implements Interface > extends
    By Bigfatcat in forum New To Java
    Replies: 8
    Last Post: 01-08-2012, 09:57 AM
  3. Extends a class that implements an interface
    By monocole in forum New To Java
    Replies: 2
    Last Post: 12-27-2011, 04:55 AM
  4. Advanced extends and implements
    By V1C3M4N in forum Advanced Java
    Replies: 15
    Last Post: 11-17-2010, 02:28 PM
  5. Implements MyClass extends JFrame
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 04:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •