简体   繁体   English

为什么java.sql.Statement是接口而不是抽象类?

[英]Why is java.sql.Statement an interface and not an abstract class?

Why is java.sql.Statement an interface and not an abstract class? 为什么java.sql.Statement是接口而不是抽象类? Some arrogant interviewer rejected a candidate because he didn't know. 一些傲慢的面试官拒绝了候选人,因为他不知道。

因为没有任何东西可以作为默认实现提供,所以它可以与世人所知的任何数据库引擎一起使用。

It is hard to say. 这很难说。 They could make it a dummy abstract class that would do pretty much nothing. 他们可以使它成为虚拟的abstract class ,几乎什么也不做。 By doing that it would make the all real implementations unable to extend any other class. 这样做会使所有实际实现无法扩展任何其他类。 An interface on the other hand is so much cleaner. 另一方面, interface要干净得多。

可能是因为作者认为不需要进行任何方法的实现。

Pretty much Statement is a skeleton class (interface) so that database driver developers knows what they need to implement when they implements Statement. 几乎Statement是一个框架类(接口),因此数据库驱动程序开发人员知道在implements Statement时需要实现什么。

As part of the JDBC API Statement couldn't be abstract as there wasn't any way they could have have "default" implementations that could range all databases. 作为JDBC API Statement一部分,它不能是抽象的,因为它们没有任何方式可以具有可以覆盖所有数据库的“默认”实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM