实战 .Net 数据访问层 - 5

代码 4 :我的 Data Entity – 2 , Framework 中的 Data Entity

// DafBase :提供大部分应用程序所需的基本 Data Entity 支持,

// 包括 Collection , ADO.NET ** **

[ ** Serializable ** ()]

public abstract class ** DefBase ** : ** IList ** , ** IDictionary **

{

protected internal string _typeEntity = ** EntityType ** .OBJECT;

// Collection fields

protected internal ** ArrayList ** _al = null ;

protected internal ** Hashtable ** _ht = null ;

// ADO.NET fields

protected internal ** DataSet ** _dst = null ;

protected internal ** DataTable ** _tbl = null ;

[ ** NonSerialized ** ()]

protected internal ** DbDataReader ** _rdr = null ;

public ** DefBase ** () { }

public ** DefBase ** ( ** ArrayList ** al)

{

this ._al = al;

this ._typeEntity = ** EntityType ** .COLLECTION_ARRAYLIST;

}

...

public ** DefBase ** ( ** DataSet ** dst)

{

this ._dst = dst;

this ._typeEntity = ** EntityType ** .ADOX_DATASET;

}

public ** DefBase ** ( ** DataTable ** tbl)

{

this ._tbl = tbl;

this ._typeEntity = ** EntityType ** .ADOX_TABLE;

}

...

}


以上,就是我的 Data Entity 小样了(终于又要见人了 J ),是不

是感觉很“酷”啊 ?

坦率地讲,根据我的保守估计,八成以上的朋友会有“不敢苟同”之想法,而另外 15% 可能是不能确定,总有似曾相识(四不象?)却又不尽相同的味道。至于这剩下的 5% ,我就不是很清楚了(希望是所见略同吧),如果哪位写邮件告诉我“这正是我想要的,请你给我一份源码吧”,估计我会毫不犹豫的立即奉上而不再考虑任何 License 问题(如果在 1 天内没有收到回复,请您相信是作者开心得晕过去了,要不就是 Internet 出问题了 J )!

Ok ,简单解释一下:

可能大家已经注意到一个问题,这里的 Def 好像并不是 Data

Entity 的缩写,那么,这个“ ** f ** ”到底代表什么呢?

前面曾经提过,作者的这个数据访问层解决方案起名字为 Data Access Façade ( DAF ),参考的当然是 GOF23 条中的 ** Façade ** Pattern ,所以,有鉴于此,这里 Def 中的“ f ”同样包含着 Façade 意思!

是不是有点复杂了?头晕?没有关系,且听一一道来!

代码 2 中给出的两种经典 Data Entity 模式各有其明显的优缺点,基本上,就作者了解的情况,实际开发中都是以一种统一的方式进行抉择,难免就顾此失彼(总有些 Case 是 简单 的,也总有些 Case 是让人 头疼 不已的)。如果,再加上系统架构时必须考虑的其它因素,如:安全,性能,可扩展性(接口 / 基类),可伸缩性(负载均衡 / 分布式处理)等,对于一个稍微上点规模的 Enterprise Application ,也就不难理解为何 Data Access Layer 总是那么让人又爱又恨了( Sigh , Data Entity 才只是万里长征第一步啊 L ) !

所以,为了解决这个问题,作者感觉有必要搞一个相对比较 Generic 的解决方案,所要解决的第一个问题就是: Data Entity !

所谓的 ** Def ** ,当然就是: ** Data Entity Façade ** ,说白了,就是以一

致的方式将数据展现在您的面前!这里的一致,不仅仅意味在当前应用程序中表现出一致的访问方式( Interface ),还要能够确保在一致的 Interface 下支持不同的 Data Entity 模型( Storage )。而所有这一切,都被隐藏在了一个特别搭建的 Data Entity 之后,它,就是作者 DAF 解决方案中的第一步: Data Entity Façade !简称为: Def 。

下一段: http://www.csdn.net/develop/Read_Article.asp?id=27548

Published At
Categories with Web编程
Tagged with
comments powered by Disqus