在C#中实现的基于外观或门面模式打造的业务应用案例
以前一直没有想过写一些东西来把项目中用到的知识点及技术实现做一个归纳整理并分享出来。现在打算逐渐的把项目中的一些东西整理并分享出来,与大家共勉!
外观或门面模式相比大家都比较清楚了,现在就该模式在实际项目中的应用做一个实例分享。
外观或门面模式的核心点就是表现层直接依赖于这里的实现,外观里直接引用工厂装配的业务类结果,屏蔽了业务类的实现,
一般常规外观模式都这样,但基于经验这里也可以留一个口子,让这里也能够间接的改变工厂装配业务类结果,便于灵活应用。
下面就拿实际项目WMS中的一个模块仓库管理来与大家分享,先简单描述下实现思路:
1、定义外观类BizFacadeWarehouse,该类负责暴露业务工厂结果给表现层,也就是上节选定的业务类4个功能方法
2、在该类的构造函数中,通过业务工厂的Create方法来初始化抽象业务类,也就是依据应用来选定具体实现
3、BizFacadeWarehouse类定义
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Warehouse.Biz;
using Warehouse.BizFactory;
using Entitys.ComonEnti;
using Common;
using FrameCommon;
using Warehouse.Entities;
namespace Warehouse.BizExecFacade
{
public class BizFacadeWarehouse
{
BizFactoryWarehouse comWarehousebizF = new BizFactoryWarehouse();
Warehousebiz comWarehousebiz = null;
public string err = string.Empty;
public BizFacadeWarehouse(SysEnvironmentSerialize _envirObj)
{
string _currlang = _envirObj.I18nCurrLang;
try
{
this.comWarehousebiz = this.comWarehousebizF.Create("one", _envirObj);
}
catch (Exception ex)
{
err = ex.ToString();
}
}
/// <summary>
/// 获取数据库仓库
/// </summary>
/// <param name="warehouse"></param>
/// <param name="ddnmParams"></param>
/// <param name="errStr"></param>
/// <param name="ListBizLog"></param>
/// <returns></returns>
public List<WAREHOUSE> GetWarehouses(WAREHOUSE warehouse, DistributeDataNodeManagerParams ddnmParams, List<string> errStr, List<SSY_LOGENTITY> ListBizLog)
{
return this.comWarehousebiz.GetWarehouses(warehouse, ddnmParams, errStr, ListBizLog);
}
/// <summary>
/// 获取数据库仓库货架
/// </summary>
/// <param name="bizobj"></param>
/// <param name="ddnmParams"></param>
/// <param name="errStr"></param>
/// <param name="ListBizLog"></param>
/// <returns></returns>
public List<STORAGE_RACK> GetStorage_racks(STORAGE_RACK bizobj, DistributeDataNodeManagerParams ddnmParams, List<string> errStr, List<SSY_LOGENTITY> ListBizLog)
{
return this.comWarehousebiz.GetStorage_racks(bizobj, ddnmParams, errStr, ListBizLog);
}
/// <summary>
/// 获取数据库仓库货架区域
/// </summary>
/// <param name="bizobj"></param>
/// <param name="ddnmParams"></param>
/// <param name="errStr"></param>
/// <param name="ListBizLog"></param>
/// <returns></returns>
public List<STORAGE_RACK_ZONE> GetStorage_rack_zones(STORAGE_RACK_ZONE bizobj, DistributeDataNodeManagerParams ddnmParams, List<string> errStr, List<SSY_LOGENTITY> ListBizLog)
{
return this.comWarehousebiz.GetStorage_rack_zones(bizobj, ddnmParams, errStr, ListBizLog);
}
/// <summary>
/// 获取绑定记录
/// </summary>
/// <param name="bizobj"></param>
/// <param name="ddnmParams"></param>
/// <param name="pager"></param>
/// <param name="errStr"></param>
/// <param name="ListBizLog"></param>
/// <returns></returns>
public List<PACK_BINDING> GetPack_bindingPager(PACK_BINDING bizobj, DistributeDataNodeManagerParams ddnmParams, SSY_PagingParam pager, List<string> errStr, List<SSY_LOGENTITY> ListBizLog)
{
return this.comWarehousebiz.GetPack_bindingPager(bizobj, ddnmParams, pager, errStr, ListBizLog);
}
}
}
获取实例源码请入QQ群706224870,在群文件中下载。