开发者

Implementing interface correct terminology

If I have a method that has as argument a Base class type I can pass it every object of a class that has extended that base class because a derived class is also a base class.

So if I have a method that has as argument an Interface type I can pass it every object of a class that has implemented that interface because that class is also an interface or all the interfaces it can implement.

Is that t开发者_运维百科he correct terminology to use with the interface?

Thanks.


Correct terminology would not be

that class is also an interface

but

that class can behave exactly as the interface promises

instead.

With bases classes, it is like "I can work with any hard worker." With interfaces, it is like "I can work with anything that works hard."


that class is also an interface I don't agree with this line. That class is not an interface, that class just have implemented that interface. In my opinion this statement that class is also an interface would be wrong


More precise formulations would be "any instance of a class D that derives from a base class B is also an instance of B", and "any instance of a class D that implements an interface I may also be referenced through I". This way of phrasing it makes a clear distinction between class, interface, and instance.


that class is also an interface

I wouldn't express it that way (mainly because a class is not an interface). I'd express it like that:

  • .. that class provides the API of the interface ..
  • .. that class provides the behavior defined by the interface
  • .. that class implements the interface ..
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜