public class Request
implements HttpServletRequest {
// ...
protected RequestFacade facade = null;
// ...
/**
* Return the <code>ServletRequest</code> for which this object
* is the facade. This method must be implemented by a subclass.
*/
public HttpServletRequest getRequest() {
if (facade == null) {
facade = new RequestFacade(this);
}
return facade;
}
}
org.apache.catalina.connector.RequestFacade
public class RequestFacade implements HttpServletRequest {
// ...
}
Spring中对外观模式的使用
org.springframework.jdbc.support.JdbcUtils
在 JdbcUtils 封装了对 java.sql.Connection 的使用;
JdbcUtils 和 java.sql.Connection 都属于抽象层的依赖关系;
public abstract class JdbcUtils {
// ...
public static void closeConnection(Connection con) {
if (con != null) {
try {
con.close();
}
catch (SQLException ex) {
logger.debug("Could not close JDBC Connection", ex);
}
catch (Throwable ex) {
// We don't trust the JDBC driver: It might throw RuntimeException or Error.
logger.debug("Unexpected exception on closing JDBC Connection", ex);
}
}
}
// ...
}