每次实现PooledConnection时,我们都会编写

class MyConnection implements PooledConnection, Connection {
  // implement methods of PooledConnection and Connection
}

我想知道为什么PooledConnection没有设计为extends Connection吗?因为毕竟PooledConnection始终是Connection

最佳答案

我不太确定,但是我想知道PooledConnection不扩展Connection的原因是,您可以制作一个使用任何其他现有PooledConnection实现的非常简单的Connection实现,从而允许代码重用并保持功能独立。

10-08 17:09