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 the 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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.