How to explain interface of an object?
Interface are only used for implementing classes and hence forth we write it as follows
Suppose we have class Car and interface named Model
then we can write
Interface is a contract you can say to be more precise
I am not asking about Interfaces in java, i am asking from general OOP point of view. A Class has an object and this object has some interface associated with it, which
tells that object what to do and how to do?
this is my point.
sorry and i shall take care from now on.
Thanks for suggestion.
David Newton wrote:An interface is a type of contract: a class that implements an interface must, at minimum, include implementations of the interface.
Just keep in mind what David said. Is a type of contract. When a concrete class implements it, it will must implement it's methods.
Ok i got the point, Thank you Vishal Hegde, Pratik D mehta, David Newton, and Hebert Coelho for your valuable replies.
Harnoor Singh wrote:Interface of the object is the method/methods through which it interacts with other objects or other part of program.
Absolutely this is what i was looking for, Thanks Harnoor Singh.
now my next question is that, is it right to say that we inherit interface of an object in inheritance and we do not inherit interface of an object in composition?
(It *can*, but in Java needs to be done manually, usually by delegating method calls to the property that implements the interface. Most IDEs can do this busy work automatically.)
David Newton wrote:Correct: simply having a property that implements an interface doesn't mean the class now implements that same interface.
:thumbup: thank you David