Step by step to resolve six, BLL design for the three-tier architecture camp .NET

      BLL layer, also called business logic, by definition, is a place to put the business logic.

     Position in the business logic layer of the architecture is critical, it is in the middle of a data access layer and the presentation layer, data exchange plays a connecting role. Since the layer is a weak coupling structure, the dependency between layers is downwards, the bottom for the upper layer is "ignorant" of changing the design of the upper layer has no effect on the bottom in terms of their call. If the layered design, follow the ideology-oriented interface design, then this should also be down a weak dependence dependency. Thus, without changing the interface definition premise, preferably layered architecture should support a removable, replaceable "drawer" architecture. Because of this, the business logic is designed to support a scalable architecture is particularly critical because it plays two different roles. For data access layer, it is the caller; for the presentation layer, it is the caller. Dependence and is dependent on the business logic tangled relationships, how to decouple dependencies, it is left to implement business logic in addition to the designer's task.

     Besides point digression here for your entertainment next.

     Martin Fowler in "Enterprise Application Architecture," a book in the field of architectural pattern layer (ie, business logic layer) made overall summary of his business logic design is divided into three main modes: Transaction Script, Domain Model and Table Module .

    Transaction Script mode logic as an a business process, a typical process-oriented development model. Application Transaction Script pattern may not require data access layer, but to use SQL statements directly access the database. In order to effectively manage the SQL statement, and database access related behaviors can put a special Gateway class. Application Transaction Script mode does not require much knowledge of object-oriented, straightforward feature is where the full value of the mode. Thus, a relatively simple business logic in many projects, more often Transaction Script mode.

    Domain Model pattern is reflected in the typical object-oriented design ideas. It fully takes into account the complex business logic, such as the introduction of the Strategy pattern design mode of thought, and by creating domain objects and abstract interface, scalability model, and object-oriented ideology born to features such as inheritance , encapsulation and polymorphism, complex business logic for processing. The only restriction is that the model application mapping objects to relational databases. We can introduce ORM tool, or use the Data Mapper pattern to complete the mapping relationship to objects.

    And Domain Model pattern is similar to Table Module pattern, it also has object-oriented design idea, the only difference is that the object is not simply to get the domain objects, but the DataSet object. If you create a simple mappings between relational tables and objects, then the Domain Model pattern is to set up a field object for each data record in the table, while Table Module pattern sucked the entire table is treated as a complete object. Although the use of the DataSet object will be lost object-oriented basic characteristics, but it is a data source that provides support layer aspects, it has a unique advantage. Especially in the .Net platform, ADO.NET and Web controls provide fertile soil for the growth of the Table Module pattern.

Into the topic, and we have to customSystem.cs design:

 public class customSystem
    {
        public ICustom CustomSQL = new customSQL();
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="Custom"></param>
        /// <returns></returns>
        public int customADD(custom Custom)
        {
            if (Custom == null)
            {
                return 0;
            }
            return CustomSQL.Addcustom(Custom);
        }
        /// <summary>
        /// 根据帐户名获取用户信息
        /// </summary>
        /// <param name="nename"></param>
        /// <returns></returns>
        public custom GetSinglename(string nename)
        {
            if (string.IsNullOrEmpty(nename))
                return null;
            return CustomSQL.Getsinglecname(nename);
        }
        /// <summary>
        /// 更新用户信息(主要用于更改密码)
        /// </summary>
        /// <param name="Custom"></param>
        public void Updatepassword(custom Custom)
        {
            if (Custom == null)
                return;
            CustomSQL.Updatepassword(Custom);
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <returns></returns>
        public List<custom> GetCustom()
        {
            return CustomSQL.Getcustom();
        }
        /// <summary>
        /// 根据ID删除用户信息
        /// </summary>
        /// <param name="nid"></param>
        public void Deletecustom(int nid)
        {
            if (nid <= 0)
                return;
            CustomSQL.Deletecustom(nid);
        }
        /// <summary>
        /// 根据ID获取用户信息
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        public custom GetCutomer(int nid)
        {
            if (nid <= 0)
                return null;
            return CustomSQL.Getcustomer(nid);
        }
        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="Custom"></param>
        public void updatecustom(custom Custom)
        {
            if (Custom == null)
                return;
            CustomSQL.updatecustom(Custom);
        }
        /// <summary>
        /// 根据部门ID获取整个部门用户
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        public List<custom> Getdepartcustom(int nid)
        {
            if (nid <= 0)
                return null;
            return CustomSQL.Getdepartcustom(nid);
        }
    }

接着我们再来看下departmentSystem.cs的设计:

   public class departmentSystem
    {
        public IDepartment DepartmentSQL = new departmentSQL();
        /// <summary>
        /// 添加一条部门信息
        /// </summary>
        /// <param name="Department"></param>
        /// <returns></returns>
        public int Adddepartment(department Department)
        {
            if (Department == null)
                return 0;
            return DepartmentSQL.Adddepartment(Department);
        }
        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <returns></returns>
        public List<department> GetDepartment()
        {
            return (DepartmentSQL.Getdepartment());
        }
        /// <summary>
        /// 根据部门ID获取部门信息
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        public department Getsingledepartment(int nid)
        {
            if (nid <= 0)
                return null;
            return DepartmentSQL.Getsingledepartment(nid);
        }
        /// <summary>
        /// 根据部门名字获取部门信息
        /// </summary>
        /// <param name="ndepartname"></param>
        /// <returns></returns>
        public department Getdepartmenter(string ndepartname)
        {
            if (string.IsNullOrEmpty(ndepartname))
                return null;
                return DepartmentSQL.Getdepartmenter(ndepartname);
        }
        /// <summary>
        /// 更新部门信息
        /// </summary>
        /// <param name="Department"></param>
        public void updatedepart(department Department)
        {
            if (Department == null)
                return;
            DepartmentSQL.Updatepartment(Department);
        }
        /// <summary>
        /// 根据ID删除部门数据
        /// </summary>
        /// <param name="nid"></param>
        public void Deletedepart(int nid)
        {
            if (nid <= 0)
                return;
            DepartmentSQL.Deletedepart(nid);
        }

    }
The BLL we have a good design, then we will carry out the design of the UI, we start with the landing page design from it, if you have any good suggestions, please reply to communicate with me, please Paizhuan.





Reproduced in: https: //www.cnblogs.com/springyangwc/archive/2011/03/26/1996614.html

Guess you like

Origin blog.csdn.net/weixin_34195546/article/details/93340867