国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 12:50:38
字體:
來源:轉載
供稿:網友

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

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

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

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

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

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

我們的實體類將放在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
大家可以看出,實體類的代碼很簡單,僅僅是負責實體的表示和數據的傳遞,不包含任何邏輯性內容。

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灵川县| 濉溪县| 鲁甸县| 班戈县| 汉中市| 新闻| 万盛区| 杂多县| 内黄县| 唐海县| 得荣县| 尖扎县| 沙河市| 灵石县| 乌兰浩特市| 万荣县| 安康市| 孙吴县| 台南县| 南皮县| 潮安县| 常熟市| 宝坻区| 尼勒克县| 芒康县| 温宿县| 宝清县| 玉林市| 五华县| 宜城市| 汤阴县| 无锡市| 托克逊县| 阳高县| 岚皋县| 临安市| 沽源县| 庆元县| 连云港市| 泸州市| 琼中|