Is there any relation between the class that implements interface and that interface?

后端 未结 8 783
有刺的猬
有刺的猬 2020-12-19 16:56

Consider this class hierarchy:

  • Book extends Goods
  • Book implements Taxable

As we know, there is a relationship

相关标签:
8条回答
  • 2020-12-19 17:11
    Book implements Taxable
    

    Here also the relationship between Book and Taxable is

    Book 'is a' Taxable

    Refer this. You can see it says

    When we talk about inheritance the most commonly used keyword would be extends and implements. These words would determine whether one object IS-A type of another.

    0 讨论(0)
  • 2020-12-19 17:12

    What's all the excitement about? The multiple question marks and multiple exclamation points?

    Does it bother you that we can say a Book is Taxable, even though Taxable is an interface? Please calm down.

    There are different keywords in the language for a class' relationship to an interface and to a superclass, but the conceptual nature of that relationship is the same, therefore it's entirely reasonable to use the same English terms to describe it. A Book is Taxable, just as a Book is a Good. To bring the terms even closer, a Book is a TaxableItem. It's OK.

    0 讨论(0)
  • 2020-12-19 17:14

    Well there's "supports-the-operations-of". Personally I don't find the "is-a", "can-do" etc mnemonics to be terribly useful. I prefer to think in terms of what the types allow, whether they're specialising existing behaviour or implementing the behaviour themselves etc. Analogies, like abstractions, tend to be leaky. If you know what the different between interface inheritance and implementation inheritance is, you probably don't need any extra phraseology to express it.

    0 讨论(0)
  • 2020-12-19 17:19

    When we say one class extends another class it is having strong relation ship known as 'inheritance'.this means when one child extends parent then child should be able to inherit something from parent class like horse IS A animal .Horse is inheriting some properties of animal .But when a class implements another class then child class is trying to implement a contract dosen't need to inherit anything from parent just following a contract ,that why interface all methods are abstract by default but you can provide some concrete method in class(for child class to inherit) and can make some of then abstract is well .

    So for me extends is inheritance and interface in implementing contract.hope this is satisfactory

    0 讨论(0)
  • 2020-12-19 17:23

    the relationship would be as stated: 'implements'

    these relationship names spring from usage in sentences. "Book 'is-a' Goods" can be written without the quotes and hyphen and it makes sense. similarly, Book 'implements' Taxable can be written without the quotes.

    0 讨论(0)
  • 2020-12-19 17:28

    Yes. The relationship is exactly the same

    Book is a Taxable too.

    EDIT

    An interface is an artifact that happens to match Java's ( and probably C# I don't know ) interface keyword.

    In OO interface is the set of operations that a class is 'committed' perform and nothing more. Is like a contract between the object class and its clients.

    OO programming languages whose don't have interface keyword, still have class interface OO concept.

    0 讨论(0)
提交回复
热议问题