当前位置: 代码迷 >> 设计模式 >> .net机房收费系统范例—三层+设计模式
  详细解决方案

.net机房收费系统范例—三层+设计模式

热度:7656   发布时间:2013-02-26 00:00:00.0
.net机房收费系统实例—三层+设计模式

   最近在做.net机房收费系统,和简单的三层来一个对比,现在贴出来和大家分享!


包图:

   

    应用了设计模式(抽象工厂),这样使得B层和D层之间无需再有关系(应用接口),应用了抽象工厂+反射+配置文件,使得工厂和D层的关系线消失,这样B层和工厂只需知道D层的接口,和D层解耦。


类图在这里就省略了!


时序图:

          

下面则是实现的代码,当然只是简单的用上图的架构实现了登录的功能,时序图中的一些逻辑处理还没有应用.


U层:

Public Class Form    Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butExit.Click        End    End Sub    Private Sub butLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butLogin.Click        '定义一个实体类对象,将文本框中的内容赋给实体类对象        Dim user As Model.Teacher = New Model.Teacher        user.user_ID = txtUserID.Text.ToString()        user.user_PWD = txtUserPWD.Text.ToString()        '定义一个业务逻辑层对象,根据业务逻辑层返回的结果,通知用户信息        Dim fd As Facade.UserF = New Facade.UserF        If fd.Query(user) Then            MsgBox(True)        Else            MsgBox(False)        End If    End SubEnd Class


Facede层:

Public Class UserF    Dim uB As BLL.UserBLL = New BLL.UserBLL    Function Query(ByVal user As Model.Teacher) As Boolean        If uB.QueryUser(user) Then            Return (True)        Else            Return (False)        End If    End FunctionEnd Class


B层

Public Class UserBLL       Dim factory As Factory.UserFactory = New Factory.UserFactory    Dim IUserDAL As IDAL.IUserIDAL    Public Function QueryUser(ByVal user As Model.Teacher) As Boolean        IUserDAL = factory.CreateUserDAL()        If IUserDAL.Query_user(user) Then            Return (True)        Else            Return (False)        End If    End FunctionEnd Class


Factory层

Imports System.ReflectionImports System.ConfigurationPublic Class UserFactory        Public Function CreateUserDAL() As IDAL.IUserIDAL        Dim AssemblyName = "DAL"        'Dim create = "User"        Dim create As String = ConfigurationManager.AppSettings("create")        Dim className As String        'Dim user As DAL.UserDAL = New DAL.UserDAL        'Return user        className = AssemblyName + "." + create + "DAL"        Return CType(Assembly.Load(AssemblyName).CreateInstance(className), IDAL.IUserIDAL)    End FunctionEnd Class


IDAL层

Imports ModelPublic Interface IUserIDAL    Function Query_user(ByVal user As Teacher) As BooleanEnd Interface

          学习的过程就是不断反复,不断对比,我们也是在不断的跌跌撞撞中成长,正是这样的成长,让我们逐步的去认识新的事物,了解它,以致掌握它!




3楼waterliu2003昨天 14:55
新手,学习中。。。
2楼wss784616158昨天 13:48
真专业!
Re: hejingyuan6昨天 14:11
回复wss784616158n呵呵
1楼liutengteng130昨天 10:41
学习了,加油啊。
  相关解决方案