这一章是项目架构中的重点.主要说的是builder这个类.这个类用到了建造者模式.我在项目中把它作为整个项目的逻辑控制类.它向上提供了一个方法,向下起到了各个具体业务类的流程控制.同时考虑到扩展性,它实现为一个接口:
1 public interface IBuilder
2 {
3 BuilderResult Execute();
4 }
2 {
3 BuilderResult Execute();
4 }
可以看到调用builder的地方只有一句语句:
1 BuilderResult Execute();
下面是这个函数的实现
1 public virtual BuilderResult Execute()
2 {
3 string ErrMessage=string.Empty ;
4 BuilderResult result=new BuilderResult();
5 try
6 {
7 result=beforExecute();
8 if (State.Success ==result.ResultState )
9 {
10 result=TranTableExecute();
11 }
12 else
13 {
14 if (State.Error ==result.ResultState)
15 {
16 result.WriteLog (log);
17 }
18 }
19 }
20 catch
21 {
22 throw;
23 }
24 return result;
25 }
2 {
3 string ErrMessage=string.Empty ;
4 BuilderResult result=new BuilderResult();
5 try
6 {
7 result=beforExecute();
8 if (State.Success ==result.ResultState )
9 {
10 result=TranTableExecute();
11 }
12 else
13 {
14 if (State.Error ==result.ResultState)
15 {
16 result.WriteLog (log);
17 }
18 }
19 }
20 catch
21 {
22 throw;
23 }
24 return result;
25 }
调用接口函数:
1 protected bool ValidAskFileName(out string ErrMessage)
2 {
3 if (null==tran)
4 tran=CreateTran();
5 return tran.ValidAskFileName (out ErrMessage);
6 }
2 {
3 if (null==tran)
4 tran=CreateTran();
5 return tran.ValidAskFileName (out ErrMessage);
6 }
调用接口函数2:
1 /// <summary>
2 /// 执行业务类
3 /// </summary>
4 private TranResult ExecuteTran()
5 {
6 TranResult result=null;
7 try
8 {
9 detail.TranDataTable =tempTable;
10
11 result=tran.CheckValid();
12 if (TranState.Success ==result.ResultState)
13 {
14 result =tran.ImportData();
15 }
16 }
17 // catch(Exception ex)
18 // {
19 // throw new TranException (ex.Message,ex);
20 // }
21 finally
22 {
23 //报告消息,完成一笔数据
24 //OnRateReport (new RateReportEventArgs(Convert.ToInt32 (SR.ReportOfDataExcute)));
25 result.WriteLog (tempTable,log);
26 tempTable.Clear ();
27 }
28 return result;
29 }
2 /// 执行业务类
3 /// </summary>
4 private TranResult ExecuteTran()
5 {
6 TranResult result=null;
7 try
8 {
9 detail.TranDataTable =tempTable;
10
11 result=tran.CheckValid();
12 if (TranState.Success ==result.ResultState)
13 {
14 result =tran.ImportData();
15 }
16 }
17 // catch(Exception ex)
18 // {
19 // throw new TranException (ex.Message,ex);
20 // }
21 finally
22 {
23 //报告消息,完成一笔数据
24 //OnRateReport (new RateReportEventArgs(Convert.ToInt32 (SR.ReportOfDataExcute)));
25 result.WriteLog (tempTable,log);
26 tempTable.Clear ();
27 }
28 return result;
29 }
在这个函数中, builder起到了控制业务逻辑的作用,当然其中的业务类也是由接口实现的.
在这里,我主要想就分层说说我的看法:
为了能够更有效的对企业中的各种逻辑进行组织,我们使用层技术来实现企业应用。层技术在计算机领域中有着悠久的历史,计算机的实现中就引用了分层的概念。TCP/IP的七层协议栈也是典型的分层的概念。分层的优势在于:
上层的逻辑不需要了解所有的底层逻辑,它只需要了解和它邻接的那一层的细节。我们知道TCP/IP协议栈就是通过不同的层对数据进行层层封包的,
不同层间的耦合度明显降低。通过严格的区分层次,大大降低了层间的耦合度。
某一层次的下级层可以有不同的实现。例如同样的编程语言可以在不同的操作系统和不同的机器中运行。
同一个层次可以支持不同的上级层。TCP协议可以支持FTP、HTTP等应用层协议。
在这个项目中,我主要的思想就是利用了分层的思想,因为有了接口,分层的目的在实现上可以很容易达到.