开发者

Where did java get the idea for Interfaces from?

开发者 https://www.devze.com 2023-01-18 23:55 出处:网络
开发者_如何学编程I\'m aware that most things in modern programming languages are at least partially based on features in earlier languages.
开发者_如何学编程

I'm aware that most things in modern programming languages are at least partially based on features in earlier languages.

This leads me to wonder where java got the inspiration for interfaces from. Was it mostly their own creation? Was it based on fully Abstract Base classes(with multiple inheritance) ?


In a recent Objective-C book I was reading Learn Objective-C on the Mac, the authors suggest that the primary inspiration for Java's interfaces are from Objective-C's implementation of Formal Protocols.

Formal Protocols in Obj-C are files, just like Java's Interfaces, that are filled with abstract methods – or plainly just the method headers – that the developer must implement if the Formal Protocol is used. In the most recent update to Apple's Cocoa, Formal Protocols can also include optional methods which the developer doesn't need to implement if the class implements the protocol.


I think the designers of Java realized that there are a lot of flaws in using multiple implementation inheritance, but still wanted to be able to multiply inherit. Thus, the solution was multiple interface inheritance.

Also, from the previous link:

Instead, Java's designers chose to allow multiple interface inheritance through the use of interfaces, an idea borrowed from Objective C's protocols. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods.

So, Sean is indeed correct.


Actually It comes from the idea of multiple inheritance and abstract class. Our dear Mr. Goslin did not wanted the multiple inheritance in class level.

0

精彩评论

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