Interface Contract, Class Object?

后端 未结 6 1663
旧巷少年郎
旧巷少年郎 2020-12-25 14:17

Is contract to interface as object is to class?

What is the need to differentiate identical things like this, from the code to the executing code? I sort of get the

6条回答
  •  一整个雨季
    2020-12-25 14:35

    No, not really. A class is a template that you define. Each object that instantiates that class follows the template. They're not really redundant terms, because the two things are not identical. You can think of a class as a user-defined data type. Classes and objects are different from each other in the exact same way that the primitive data type int is different from the literal value 3.

    An interface defines a set of methods that all implementing classes must support. The interface itself is the contract that you define for the implementing classes. It just says that any class that implements the interface, must have that interface's set of public methods.

提交回复
热议问题