petshop3.0构架介绍/petShop4.0解剖

 petshop是C#实现的petstore,具体和技术无关的情况就不多介绍了。

现在基于.Net 2.0的PetShop4.0为止,整个设计逐渐变得成熟而优雅,却又很多可以借鉴之处。PetShop是一个小型的项目,系统架构与代码都比较简单,却 也凸现了许多颇有价值的设计与开发理念。petShop4.0解剖
petshop3.0比petshop1和2都有了较大的改变,主要是设计方面的。看一下里面的8个工程和1个站点就知道它肯定分了不少层。
一.概况介绍。
Model:
模型层,封装业务实体,一般和数据库模式对应。
例如:
      

public   class  AccountInfo  {
 
              
// Internal member variables
              private string _userId;
              
private string _password;
              
private string _email;
              
private AddressInfo _address;
              
private string _language;
              
private string _category;
              
private bool _showFavorites;
              
private bool _showBanners;
              。。。
       }

IDAL:
数据访问接口层,主要是一些dao接口。
例如:
      
  public   interface  IAccount
       
{
              AccountInfo SignIn(
string userId, string password);
              AddressInfo GetAddress(
string userId);
              
void Insert(AccountInfo account);
              
void Update(AccountInfo Account);
       }

 
OracleDAL:
oracle实现的数据访问层。
 
SQLServerDAL:
sql实现的数据访问层。
OracleDAL和SQLServerDAL中的类都实现了IDAL中的接口。属于dao实现。
 
DALFactory
负责确定是使用oracle实现还是mssql实现。通过在web.config中的配置确定使用哪一个dal实现(通过反射,动态生成访问类是PetShop.SQLServerDAL还是PetShop.OracleDAL命名空间中的类)。
              
< add  key ="WebDAL"  value ="PetShop.SQLServerDAL" />
              
< add  key ="OrdersDAL"  value ="PetShop.SQLServerDAL" />
      
  public   class  Account
       
{
              
public static PetShop.IDAL.IAccount Create()
              
{                   
                     
/// Look up the DAL implementation we should be using
                     string path = System.Configuration.ConfigurationSettings.AppSettings["WebDAL"];
                     
string className = path + ".Account";
 
                     
// Using the evidence given in the config file load the appropriate assembly and class
                     return (PetShop.IDAL.IAccount) Assembly.Load(path).CreateInstance(className);
              }

       }

 
BLL:
业务访问层。通过DALFactory,读取配置,决定使用何种dal实现。
     
   public   class  Account  {          
              
public AccountInfo SignIn(string userId, string password) {
 
 
                     
if ((userId.Trim() == string.Empty) || (password.Trim() == string.Empty))
                            
return null;
 
                     
// 通过DALFactory调用具体的dal实现。
                     IAccount dal = PetShop.DALFactory.Account.Create();
 
                     
// Try to sign in with the given credentials
                     AccountInfo account = dal.SignIn(userId, password);
 
                     
// Return the account
                     return account;
              }

              。。。
}

 
Web:
表现层,主要包括了Web 页面(aspx)和用户控件(ascx)控件及自定义服务器控件SimplePager和ViewStatePager。
 
Utility:
公用模块,一组帮助器类,其他业务层和数据访问层可能会使用到的一些公用方法。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值