普通三层结构示例
解决方案结构:
1.BLL //业务逻辑层
2.DALFactory //数据访问层工厂
3.DBUtility //数据访问基础类
4.IDAL //数据访问接口层
5.Model //数据实体层
6.SQLSeverDAL //SQL数据库的数据访问层(对应实现IDAL中的接口类)
7.Web //表现层(aspx,ascx)
1.BLL:
A.News.cs类:
a.private readonly Maticsoft.IDAL.NewsManage.INews dal =DALFactory.DataAccess.CreateNews(); //从工厂里面创建产品类的数据访问对象
//INews是IDAL中的接口类,定义了增加/更新/删除/得到数据的方法。DataAccess类在DALFactory中,负责创建接口层对象
b.public void Add(Maticsoft.Model.NewsManage.News model) { dal.Add(model); } //增加一条数据
c.public Maticsoft.Model.NewsManage.News GetModelByCache(int NewsId) { ... } //从缓存中得到一个对象实体(dal接口以外的其它方法)
B.SysManage.cs类:
实现类似News.cs,负责系统的逻辑处理(如日志管理)
2.DALFactory:
A.DataAccess.cs类:
a.private static readonly string AssemblyPath = ConfigurationManager.AppSettings["DAL"];
//数据访问层程序集名称,Maticsoft.SQLServerDAL
b.public static Maticsoft.IDAL.NewsManage.INews CreateNews() { ... } //创建具体的类对象
3.DBUtility:
A.CommandInfo.cs:数据库的命令信息类
B.DBHelperSQL.cs、DBHelperOra,cs、DBHelperSQLP.cs、SQLHelper.cs、OracleHelper.cs:数据库操作类,用到CommandInfo对象
C.DBEncrypt.cs:DES加密/解密类
4.IDAL:
A.INews.cs(INewsClass.cs、IProduct.cs):
a.void Add(Maticsoft.Model.NewsManage.News model);
b.void Delete(int NewsId);
c.DataSet GetListByPage(int PageSize, int PageIndex, string strWhere); //根据分页获得数据列表
为业务罗辑层定义接口方法
B.ISysmanage.cs
a.int AddTreeNode(SysNode node);
b.void UpdateNode(SysNode node);
c.void AddLog(string time,string loginfo,string Particular);
5.Model:
News.cs(NewsClass.cs、Product.cs):数据库字段与实体类属性的映射
6.SQLServerDAL:
News.cs(NewsClass.cs、Product.cs):
a.public Maticsoft.Model.NewsManage.News GetModel(int NewsId) { ... } //返回Model对象
b.public void Add(Maticsoft.Model.NewsManage.News model) { ... } //增加一条数据
C.public DataSet GetList(string strWhere) { ... } //获取数据列表
7.Web:
A:Defualt.aspx.cs:
private void ShowNews()
{
Maticsoft.BLL.NewsManage.News bll = new Maticsoft.BLL.NewsManage.News(); //定义业务逻辑层对象
this.DataList1.DataSource = bll.GetTopScroll(4); //调用逻辑对象的方法
this.DataList1.DataBind();
}
B.业务逻辑层:BLL-NewsManage-News.cs-GetTopScroll(int):
private readonly Maticsoft.IDAL.NewsManage.INews dal = DALFactory.DataAccess.CreateNews();
//定义数据访问接口层对象(实例化成数据访问层工厂类的具体对象)
//相当于INews dal = (INews)new News(); 这时dal.add()会执行News中的具体实现方法
public DataSet GetTopScroll(int top)
{
return dal.GetTopScroll(top); //调用工厂类的具体对象的方法
}
C.数据访问层工厂:DALFactory.DataAccess.CreateNews():
public static Maticsoft.IDAL.NewsManage.INews CreateNews()
{
string classNamespace = AssemblyPath + ".NewsManage.News";
object objType = CreateObject(AssemblyPath, classNamespace); //返回SQLSeverDAL的对象(实现INews接口)
return (Maticsoft.IDAL.NewsManage.INews)objType;
}