欧美日韩精品在线,国内精品久久久久久久久,一级毛片恃级毛片直播,清纯唯美亚洲综合欧美色

基于.NET平臺的分層架構實戰(zhàn)(四)實體類的設計與實現(xiàn)_.Net教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:基于.NET平臺的分層架構實戰(zhàn)(三)架構概要設計
本文主要是對將要實現(xiàn)的架構進行一個總體的描述,使朋友們對這個架構有個宏觀上的認識。這篇文章理論性的東西會偏多一點,從下篇開始,將進行實際項目的開發(fā)。這篇文章的許多內容摘自我的畢業(yè)論

實體類是現(xiàn)實實體在計算機中的表示。它貫穿于整個架構,負擔著在各層次及模塊間傳遞數(shù)據(jù)的職責。一般來說,實體類可以分為“貧血實體類”和“充血實體類”,前者僅僅保存實體的屬性,而后者還包含一些實體間的關系與邏輯。我們在這個Demo中用的實體類將是“貧血實體類”。

大多情況下,實體類和數(shù)據(jù)庫中的表(這里指實體表,不包括表示多對多對應的關系表)是一一對應的,但這并不是一個限制,在復雜的數(shù)據(jù)庫設計中,有可能出現(xiàn)一個實體類對應多個表,或者交叉對應的情況。在本文的Demo中,實體類和表是一一對應的,并且實體類中的屬性和表中的字段也是對應的。

在看實體類的代碼前,先看一下系統(tǒng)的工程結構。

如上圖所示,在初始階段,整個系統(tǒng)包括6個工程,它們的職責是這樣的:
Web——表示層
Entity——存放實體類
Factory——存放和依賴注入及IoC相關的類
IBLL——存放業(yè)務邏輯層接口族
IDAL——存放數(shù)據(jù)訪問層接口族
Utility——存放各種工具類及輔助類

這只是一個初期架構,主要是將整個系統(tǒng)搭一個框架,在后續(xù)開發(fā)中,將會有其他工程被陸陸續(xù)續(xù)添加進來。

我們的實體類將放在Entity工程下,這里包括三個文件:AdminInfo.cs,MessageInfo.cs,CommentInfo.cs,分別是管理員實體類、留言實體類和評論實體類。具體代碼如下:

AdminInfo.cs:
AdminInfo
1using System;
2
3namespace NGuestBook.Entity
4{
5 /**//// <summary>
6 /// 實體類-管理員
7 /// </summary>
8 [Serializable]
9 public class AdminInfo
10 {
11 private int id;
12 private string name;
13 private string password;
14
15 public int ID
16 {
17 get { return this.id; }
18 set { this.id = value; }
19 }
20
21 public string Name
22 {
23 get { return this.name; }
24 set { this.name = value; }
25 }
26
27 public string Password
28 {
29 get { return this.password; }
30 set { this.password = value; }
31 }
32 }
33}
34
MessageInfo.cs:
MessageInfo
1using System;
2
3namespace NGuestBook.Entity
4{
5 /**//// <summary>
6 /// 實體類-留言
7 /// </summary>
8 [Serializable]
9 public class MessageInfo
10 {
11 private int id;
12 private string guestName;
13 private string guestEmail;
14 private string content;
15 private DateTime time;
16 private string reply;
17 private string isPass;
18
19 public int ID
20 {
21 get { return this.id; }
22 set { this.id = value; }
23 }
24
25 public string GuestName
26 {
27 get { return this.guestName; }
28 set { this.guestName = value; }
29 }
30
31 public string GuestEmail
32 {
33 get { return this.guestEmail; }
34 set { this.guestEmail = value; }
35 }
36
37 public string Content
38 {
39 get { return this.content; }
40 set { this.content = value; }
41 }
42
43 public DateTime Time
44 {
45 get { return this.time; }
46 set { this.time = value; }
47 }
48
49 public string Reply
50 {
51 get { return this.reply; }
52 set { this.reply = value; }
53 }
54
55 public string IsPass
56 {
57 get { return this.isPass; }
58 set { this.isPass = value; }
59 }
60 }
61}
62
CommentInfo.cs:
CommentInfo
1using System;
2
3namespace NGuestBook.Entity
4{
5 /**//// <summary>
6 /// 實體類-評論
7 /// </summary>
8 [Serializable]
9 public class CommentInfo
10 {
11 private int id;
12 private string content;
13 private DateTime time;
14 private int message;
15
16 public int ID
17 {
18 get { return this.id; }
19 set { this.id = value; }
20 }
21
22 public string Content
23 {
24 get { return this.content; }
25 set { this.content = value; }
26 }
27
28 public DateTime Time
29 {
30 get { return this.time; }
31 set { this.time = value; }
32 }
33
34 public int Message
35 {
36 get { return this.message; }
37 set { this.message = value; }
38 }
39 }
40}
41
大家可以看出,實體類的代碼很簡單,僅僅是負責實體的表示和數(shù)據(jù)的傳遞,不包含任何邏輯性內容。

分享:基于.NET平臺的分層架構實戰(zhàn)(二)需求分析與數(shù)據(jù)庫設計
在實際的項目中,需求分析和數(shù)據(jù)庫的設計是很重要的一個環(huán)節(jié),這個環(huán)節(jié)會直接影響項目的開發(fā)過程和質量。實際中,這個環(huán)節(jié)不但需要系統(tǒng)分析師、軟件工程師等計算機方面的專家,還需要相關領域的

來源:模板無憂//所屬分類:.Net教程/更新時間:2008-08-22
相關.Net教程