facade 提供一个接口,通过这个接口,可以使一个子系统更容易使用。

it2022-05-09  28

外观模式封装系统的复杂性来提高程序的可用性,我们经常用的是数据访问外观类,它隔离了Ado.net的复杂性。

简单的外观例子  1using System; 2using System.Data; 3using System.Data.SqlClient; 4 5namespace Gof.Test.facade 6{ 7    public class DB 8    { 9        public DB()10        {}11        public DataTable GetDataTable(string sql)12        {13            DataTable dt = new DataTable();14            SqlConnection con = new SqlConnection();15            SqlDataAdapter da = new SqlDataAdapter(sql,con);16            try17            {18                if(con.State == ConnectionState.Closed)19                {20                    con.Open();21                }22                da.Fill(dt);23                return dt;24            }25            catch(Exception ex)26            {27                throw ex;28            }29        }30    }31} 在项目的开发过程中我们就可以通过重构来逐渐的丰富我们的外面类,从而使程序开发更加的简单。 The Facade Pattern provides a interface to a set of interfaces in a subsystem. Facade defines a higherlevel interface that makes the subsystem easier to use.

转载于:https://www.cnblogs.com/nanshouyong326/archive/2007/01/04/611644.html

相关资源:C 设计模式编程中Facade外观模式的使用实例解析

最新回复(0)