Abstract Data Type and Interface

前端 未结 8 1360
小鲜肉
小鲜肉 2021-02-04 18:26

I am new to Java. What is the difference between Abstract data type and Interface.

For Example We have a ListADT

interface MyListADT {
    void          


        
8条回答
  •  借酒劲吻你
    2021-02-04 19:11

    Try to think about it like this:

    • Java interface is a type, which boils down to a set of method signatures. Any type, willing to be referenced as interface must provide implementation for these signatures. In reality, there is no behaviour contract. Your implementation can do nothing and still be 'implementing' an interface.

    • Java abstract class is a type, with partially specified behaviour whose internal implementation for some reason must be specified in his inheritor. This class does have behaviour, which can be redefined/specified in his inheritors.

    • ADT is a set of expected behaviours. You assume, that after calling adt.remove(element) you call adt.get(element) and receive null.

    The answer to your question is: just an interface is not enough to be an ADT.

    • Everything, that correctly implements your interface MyListADT is an ADT. Its external behaviour must conform the ADT concept. This means, that to be considered as ADT, your type must carry implementation, which results either in abstract class or a normal class. For example: java.util.List is an interface for an ADT, but java.util.ArrayList and java.util.LinkedList are actually ADTs, because their actual behaviour does conform the ADT concept.

提交回复
热议问题