当前位置: 首页 > news >正文

网站备案与域名备案/深圳网络推广案例

网站备案与域名备案,深圳网络推广案例,浦城 建网站,长春电商网站建设公司电话数据访问层、业务逻辑层、表示层、业务实体层; 1、数据访问层的设计:首先定义一个接口,里面定义了对一张表或一个对象的增删改查操作,然后定义一个类去实现上面的接口; 2、业务逻辑层:同样先定义一个接口,里…

数据访问层、业务逻辑层、表示层、业务实体层;

1、数据访问层的设计:首先定义一个接口,里面定义了对一张表或一个对象的增删改查操作,然后定义一个类去实现上面的接口;

2、业务逻辑层:同样先定义一个接口,里面定义各种业务逻辑,然后定义一个类去实现上面的接口;

3、表示层:引用业务逻辑层的接口,调用其中的方法;

4、业务实体层;

改进(1)

泛型的引入:首先在设计数据访问层时,第一个接口就定义为泛型接口  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace IData
{public   interface IData<T>{IList<T> GetAll();}
}

                                                                                       

 

然后每个实体类去分别实现泛型接口:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainTest;
using IData;
using System.Data.SqlClient;
namespace IDataLLimpl
{public  class CustomerDataimpl:IData<Customer>{public  IList<Customer> GetAll(){SqlConnection con = new SqlConnection(Connectionstring.str);SqlCommand cmd = new SqlCommand("select CustomerID,CompanyName from Customers", con);con.Open();SqlDataReader reader = cmd.ExecuteReader();IList<Customer> ls = new List<Customer>();while (reader.Read()){Customer c = new Customer();c.CustomerId = reader[0].ToString ();c.CompanyName = reader[1].ToString ();ls.Add(c);}con.Close();return ls;}}
}

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IData;
using DomainTest;
using System.Data.SqlClient;
using System.Configuration;
namespace IDataLLimpl
{public  class ProductDataimpl:IData<Product>{public IList<Product> GetAll(){  SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["constr"]);SqlCommand cmd = new SqlCommand("select ProductId,ProductName from Products",con);con.Open();SqlDataReader reader = cmd.ExecuteReader();List<Product> ls = new List<Product>();while (reader.Read()){Product p = new Product();p.Id = reader[0].ToString();p.Productname = reader[1].ToString();ls.Add(p);}con.Close();return ls;}}
}

 

这样一来数据访问层就基本实现了,如果以后需要增加业务对象,只需要直接继承和实现泛型接口,利于扩展,下面开始业务逻辑层的设计:

 

这里需要也需要一个接口,里面定义了一些泛型方法:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainTest;
namespace IBLL
{public  interface IBLLTest{IList<T> GetAll<T>();}
}

 

然后接着在另一个程序集里引用并实现这些泛型方法;

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainTest;
using IBLL;
using IData;
using IDataLLimpl;
namespace Bllimpl
{public  class BllimplTest:IBLLTest {private IData<T> GetObj<T>( ){if (typeof(T) == typeof(Product)){return (IData<T>)new ProductDataimpl();}else{return (IData<T>)new CustomerDataimpl();}}public   IList<T> GetAll<T>(){return GetObj<T>().GetAll();}}
}

 

客户端调用:

 

 protected void Page_Load(object sender, EventArgs e){IBLLTest h = new BllimplTest();GridView1.DataSource = h.GetAll<Customer>();GridView1.DataBind();}

 

这样一个结构就算是基本完成了;引入泛型的好处是使得程序的扩展性更强,

实例下载

另外添加工厂设计模式,通过 IoC 或者 "配置反射" 来获得具体的数据层DAL实现类,可以减少层之间的耦合,也便于数据系统的替换(多层加IOC模式);

转载于:https://www.cnblogs.com/LittleFeiHu/archive/2010/11/14/1876374.html

http://www.jmfq.cn/news/4945753.html

相关文章:

  • 做网站免费/河南做网站的
  • 什么网站免费做游戏/江北seo综合优化外包
  • 怎么用PS做网站横幅/热搜榜百度一下你就知道
  • wordpress怎样搭建外贸网站/seo实战密码第四版pdf
  • 免费做封面的网站/抖音搜索排名
  • 重庆建设集团官方网站/肇庆seo按天收费
  • 做网站一般注册商标哪个类/网址之家大全
  • 柳州住房和城乡建设部网站/良品铺子网络营销策划书
  • 临安网站设计/网站seo文章该怎么写
  • 惠州做网站的/百度搜索推广操作简要流程
  • 建设部网站官网 下载规范/品牌词优化
  • 宁波免费做网站/合肥建站公司seo
  • 网上做任务的网站有哪些/资阳市网站seo
  • 深圳做营销网站的公司简介/靖江seo要多少钱
  • 做导航网站用多大的空间/如何免费搭建自己的网站
  • 全国建设部网站/开源crm系统
  • 网站图片怎么做优化/nba录像回放
  • wordpress文章列分页/廊坊推广seo霸屏
  • 深圳宝安高端网站建设报价/站长工具seo排名查询
  • 石家庄做网站哪家公司好/指数函数图像
  • 怎么制作网站客服/阿里云免费域名
  • 网站实施要求/网络营销推广要求
  • 赌博假网站这么做/软文公司代写
  • 丹徒网站建设多少钱/爱站网备案查询
  • 营销型企业网站的建设方案/百度一下你就知道原版
  • 营销型企业网站建设案例/做网络推广工作怎么样
  • 南和邢台网站制作/目前搜索引擎排名
  • 如何查看网站是否开启gzip/seo算法是什么
  • 西安网站建设怎样/福州百度快速优化
  • 如果网站不备案/搜索引擎关键词优化有哪些技巧