读书人

模板方法方式与回调函数

发布时间: 2012-09-12 09:21:30 作者: rapoo

模板方法模式与回调函数
先上模板方法模式的类图:

代码演示:

public interface StatementCallback{      Object doWithStatement(Statement stmt);}public class JdbcTemplate {      public final Object execute(StatementCallback callback){   Connection con=null;   Statement stmt=null;   try   {        con=getConnection();        stmt=con.createStatement();        Object retValue=callback.doWithStatement(stmt);        return retValue;   }    catch(SQLException e){         ...   }    finally   {       closeStatement(stmt);        releaseConnection(con);   }}



读书人网 >软件架构设计

热点推荐