M
Mary Wenge
This seems to be a beginner's question.
We can feel the advantages of class inheritance from at lease sharing
and reusing the super class's methods. But in an interface, there are
only abstract methods, and we have implement all the methods in the
class that implements this interface, why do we still use interface?
Why don't we define the methods and write their code directly in the
class without implementing any interface or something like that? In
other words, what are the advantages of using interface? I have read
some books, in which the authors just say it's a protocol and so on. I
still can not understand the necessity of using interface. Can anybody
give me a sample to illustrate this? Thanks.
Merry Christmas!
We can feel the advantages of class inheritance from at lease sharing
and reusing the super class's methods. But in an interface, there are
only abstract methods, and we have implement all the methods in the
class that implements this interface, why do we still use interface?
Why don't we define the methods and write their code directly in the
class without implementing any interface or something like that? In
other words, what are the advantages of using interface? I have read
some books, in which the authors just say it's a protocol and so on. I
still can not understand the necessity of using interface. Can anybody
give me a sample to illustrate this? Thanks.
Merry Christmas!