BLL,DAL,OBJ和3层建筑 [英] BLL, DAL, OBJ and 3 layer architecture

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

问题描述

我的问题是关于3层建筑。

我的项目是简单地像下面,但什么惹恼了我是在我插入我的数据库中一个新的专栏中,我必须更新这些各个领域除了BLL。在presentation层,我创建了一个OBJ还有DAL里面加了DAL里面,有一个SQL查询。我必须手动更新所有这些领域。

如果我这样做是正常的方式,我把所有那些presentation层内和更新都在一个地方。

我是不是正确地应用这个3层建筑,有哪些优势,使用这种分层架构?

我的第二个问题是:

在DAL里,我通过_view收集数据。我不知道,我应该写另一BOboj对每个视图??我已经有一个BOboj类,但它不包含所有字段。

当插入数据,我有我的BOboj,然而,我使用的观点,在这种情况下上市的数据时,我应该创建每个视图或其他东西另一个BOboj_view类中使用?
什么是easyies办法做到这一点?

例如;
我有20次和40类映射到SQL Server上的每一个表,我的意见收集数据不同势表(这意味着不同的对象)。应我只是创造了40多20类重present的看法?

OBJ

 类BOboj {
        私人诠释_pid;
        私人字符串_Name;
        .......
        .......
}

DAL

  BOboj_DAL {        公共BOOL添加(BOboj OBJ)
        {
            使用(SqlConnection的CON = Connect.connect)
            {
                字符串SQL =插入到人(ID,姓名,
                 .......
                 .......
}

BBL

  BOboj_BLL {        .......
        .......
        公共BOOL添加(BOboj_DAL OBJ)
        {
            BOboj_DAL bb_dal =新BOboj_DAL();
            尝试
            {
                返回bb_dal.Ekle(OBJ);            }
            赶上(例外)
            {                扔;
            }
            最后{bb_dal = NULL; }        }        .......
        .......
}

presantaon层

 保护无效添加(对象发件人,DirectEventArgs E)
        {
            BOboj_BLL bll_ =新BOboj_BLL();            BOboj obj_ =新BOboj
            {
                名称= Name.Text,
                ..............
                ...............            };
            bll_.Add(obj_);
}

感谢您。


解决方案

  1. DA对象应当以某种方式重新present数据库模式,应严格绑定到数据库的活动。


  2. 业务层,这是地方,你应该使用特定于项目的逻辑数据操作。您的业​​务对象并不总​​是相同DA对象(请想象有两个属性的名字及姓氏DA对象,但因为一些原因,你的BO对象只有一个属性姓氏怎么一回事,因为用的名字永远不会在逻辑中使用。当业务改变主意,他们想用用名字来操作过多,你必须将它添加只有在这个层)。


  3. presentation层对象应严格绑定到的意见。不应该有任何逻辑。这些目的应仅用于显示活动中使用。


当你试图保持这个规则code它更加清晰和易于十个分量不仅对你,但尤其是对你的队友。它更容易扩展以及分离code。

请也记得,在其中使用Web服务项目的某些情况下,例如可以实现第四层与面向服务的对象。

My question is about 3 layer architecture.

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.

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

My second question is :

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.

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?

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 ?

OBJ

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 Layer

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

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

            };
            bll_.Add(obj_ );
}

Thank you.

解决方案

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

  2. 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 beacuse 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).

  3. 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 mantain not only for you but especially for your team-mates. It's easier to extend well separated code.

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天全站免登陆