Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

c# - BLL, DAL, OBJ and 3 layer architecture

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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 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).

  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 maintain 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...