Comparison of several open source project physical layer implementation

xiaoxiao2021-03-06  70

This article is first in the bloggee. Sub-source project entity layer implementation is recently seen in Duwamish7, ASP.NET Forums, Dottext several excellent open source (Microsoft official) projects because I am currently at the stage of the technical level, I Looking at these project procedures, more attention is that the specific implementation is that the architecture I first focus on the implementation of the entity layer of this three projects. The following uses simple code to compare different implementations of several projects, and then Do some simple comparisons, limited to personal levels, can't do in-depth analysis, please also comment on the prawn!

Implementation code: 1. ASP.NET Forums: Realization of the entity class:

Public class

User

{Private string _userName = string.Empty; private string _userPassword = string.Empty; public string UserName {get {return _userName;} set {_userName = value;}} public string UserPassword {get {return _userPassword;} set {_userPassword = value }}}

Realization of the collection class:

Public class

UserCollection: arraylist

{Public usercollectionofARRAYLIST (): base () {} public usercollectionofarrayList (iCollection C): base (c) {}}

Second, Dottext: Implementation of the entity class: Basically, the main difference is the implementation of the collection class's implementation:

Public class

UserCollection: CollectionBase

{Public int add (user value) {return this.list.add (value);} public bool contacts {return this.list.contains (value);} public int indexof (user value) {Return this. List.IndexOf (value);} public void Insert (int index, User value) {List.Insert (index, value);} public void Remove (User value) {List.Remove (value);} // public new KeyWordCollectionEnumerator GetENUMERATOR () // {// Return New KeywordCollectionenumerator (this); //} //// public class keywordCollectionEnumerator: IEnumerator // {// // This class is used to iterate a collection, such as need to use Forech traversal collection This interface needs to be implemented, the province // // specific implementation can be refer to Dottext implementation //}} 3, Duwamish7 This project is Microsoft officially released, so the implementation of the entity layer is pushing using Microsoft. ADO.NET technology entity class and collection classes are implemented in one:

Public class

UserCollection: DataSet

{Public UserCollectionOfDataSet () {this.BuildDataTables ();} private void BuildDataTables () {DataTable table = new DataTable ( "UserCollection"); DataColumnCollection columns = table.Columns; columns.Add ( "UserName", typeof (System.String )); Columns.add ("userpassword", typeof (system.string)); this.tables.add (Table);}}

Simple analysis: 1. There is nothing to say, mainly the ASP.NET Forums entity, mainly the collection class is to achieve the collection class by inheriting arraylist, which is the simplest, but in performance, there will be some losses because When you collect, you need to continuously carry out the boxing and unboxing operations;

Second, the dottext entity class and the ASP.NET Forum are basically the same, but the set class is achieved by implementing CollectionBase, which is more complex and requires more code quantity, but its implementation is a strong type of object. In use, there is no need to perform a boxing and unpluging operation, so in terms of performance than ASP.NET Forum, DUWAMISH7 is the use of type DataSet to implement physical layer, usually Using DataSet is a very resource, it is generally believed that using Collection will excellent performance when small data is measured, and the amount of large data is better, but many times, when we are doing applications, we read data from the database. Generally, the paging query will be made during the stored procedure, only part of the data can be said to be a small amount of data, if only from the perspective of performance, the personal tendency is the type of Dataset is not the best choice.

转载请注明原文地址:https://www.9cbs.com/read-109341.html

New Post(0)