BLL、DAL、OBJ 和 3 层架构 [英] BLL, DAL, OBJ and 3 layer architecture

查看:40
本文介绍了BLL、DAL、OBJ 和 3 层架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于 3 层架构.

My question is about 3 layer architecture.

我的项目类似于下面的内容,但是让我烦恼的是在我的数据库中插入一个新列后,我必须更新除 BLL 之外的所有字段.在表示层,我创建了一个 OBJ 以及在 DAL 内部加上在 DAL 内部,有一个 SQL 查询.我必须手动更新所有这些字段.

My project is briefly something like the below, however what annoyed me is after I insert a new column inside my database, I have to update those all fields except for the BLL. In the presentation layer, I created an OBJ as well as inside the DAL plus inside the DAL, there is an SQL query. I have to update all those fields manually.

如果我以正常"方式执行此操作,我会将所有这些都放在表示层中并在一个地方更新.

If I do it the 'normal' way, I put all those inside the presentation layer and update all in one place.

我是否正确应用了这种 3 层架构?使用这种分层架构有什么好处?

Am I applying this 3 layer architecture correctly and what are the advantages to using this layered architecture?

我的第二个问题是:

在 DAL 内部,我通过 _view 收集数据.我想知道,我应该为每个视图编写另一个 BOboj 吗??我已经有一个 BOboj 类,但它不包含所有字段.

Inside the DAL, I collect the data via _view. What I wonder, should I write another BOboj for every view??I have already has a BOboj class but it doesn't contain all fields.

插入数据时,我必须使用我的 BOboj,但是,在列出数据时,我使用的是视图,在这种情况下,我应该为每个视图或其他内容创建另一个 BOboj_view 类吗?这样做的简单方法是什么?

When inserting data, I have to use my BOboj,however, when listing data,I am using views,in this case, should I create another BOboj_view class for every views or another something ?? what is the easyies way to do that?

例如;我有 20 个视图和 40 个类映射到 sql server 上的每个表,我的视图收集数据不同的表(这意味着不同的对象).除了代表视图的 40 个类之外,我应该再创建 20 个类吗?

for example; I have 20 views and 40 class which mapped to every tables on sql server ,My views collect the data diffrent tables(that means different objects).should I creates 20 more class except of 40 which represent the view ?

目标

class BOboj {
        private int _PId;
        private string _Name;
        .......
        .......


}

DAL

BOboj_DAL {

        public bool Add(BOboj obj)
        {
            using (SqlConnection con = Connect.connect)
            {
                string sql = "insert into Persons (Id,Name,
                 .......
                 .......
}

BBL

BOboj_BLL {

        .......
        .......
        public bool Add(BOboj_DAL obj)
        {
            BOboj_DAL bb_dal = new BOboj_DAL();
            try
            {
                return bb_dal.Ekle(obj);

            }
            catch (Exception)
            {

                throw;
            }
            finally { bb_dal = null; }

        }

        .......
        .......
}

Presantaon 层

Presantaon Layer

  protected void Add(object sender, DirectEventArgs e)
        {
            BOboj_BLL bll_= new BOboj_BLL ();

            BOboj  obj_ = new BOboj 
            {
                Name = Name.Text,
                ..............
                ...............

            };
            bll_.Add(obj_ );
}

谢谢.

推荐答案

  1. DA 对象应该以某种方式代表您的数据库架构,并且应该严格绑定到数据库活动.

  1. DA Objects should represent your database schema in some way and should be strictly binded to the Database activity.

业务层是您应该使用特定于您的项目逻辑来操作数据的地方.您的业​​务对象并不总是与 DA 对象相同(请想象 DA 对象具有两个属性 Forename 和 Surname,但由于某些原因,您的 BO 对象只有一个属性 Surname,因为 Forename 从未在逻辑中使用.当业务改变主意时他们也想用 Forename 操作,你只需要在这一层添加它).

Business layer this is place where you should manipulate with data using specific to your project logic. Your business object not always is the same as DA Object (please imagine DA object with two properties Forename and Surname, but because of some reasons your BO object has only one property Surname because Forename is never used in logic. When business change their minds and they want to manipulate with Forename too, you have to add it only in this layer).

展示层对象应该严格绑定到视图.应该没有逻辑.这些对象应仅用于显示活动.

Presentation layer objects should be strictly binded to the views. There shouldn't be any logic. These objects should be used only for displaying activities.

当您尝试保留此规则代码时,它不仅对您而且对您的队友而言都更加清晰和易于维护.扩展分离良好的代码更容易.

When you try to keep this rules code it's much more clear and easy to maintain not only for you but especially for your team-mates. It's easier to extend well separated code.

还请记住,在某些情况下,例如在使用 Web 服务的项目中,可以使用面向服务的对象实现第四层.

Please also remember that in some cases for example in projects which are using web services can be implemented fourth layer with Service Oriented Objects.

这篇关于BLL、DAL、OBJ 和 3 层架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆