关于Proxy和Decorator设计模式的疑问
个人认为Proxy模式和Decorator模式在编码实现上比较相似,主要还是看具体应用的场合。例如我们经常可以看到对java.sql.Connection重新包装的代码,不知道这属于哪种设计模式呢,还请大家指点。
public MyConnection implements Connection {
private Connection m_connection = null;
public MyConnection(Connection connection) {
m_connnection = connection;
}
//增加新的方法
public Timestamp getSystemTime() {
//......
}
//覆盖已经存在的方法
public void setAutoCommit(Boolean autoCommit) throws SQLException {
//......
}
//实现其它的方法
public Boolean getAutoCommit() throws SQLException {
return m_connection.getAutoCommit();
}
//......
}