5

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.

  • go though this helpful ques - http://stackoverflow.com/questions/3737848/creating-a-loosely-coupled-scalable-software-architecture – Parag Meshram Jun 05 '13 at 10:23
  • yes it is correct implementation. Advantage of this approach is that you can catch exceptions at each level gracefully – Taj Jun 05 '13 at 10:24
  • thank u for edditing. –  Jun 05 '13 at 10:30

2 Answers2

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

wonea
  • 3,987
  • 17
  • 71
  • 134
Piotr Czarnecki
  • 1,618
  • 3
  • 13
  • 22
  • thank you your answer.what do you think about this question as well.http://stackoverflow.com/questions/16936761/bll-dal-bo-inserting-data –  Jun 05 '13 at 11:11
  • @Sakir - I'm confused about your second question from link you provided. Don't understand what exactly you need to do. – Piotr Czarnecki Jun 05 '13 at 11:24
  • for example ,via view,I collect the personel information joining diffrent tables,however I have also a table person and a person class,that different from what view collected. should I creat a new class for this purpose –  Jun 05 '13 at 11:30
  • I unerstand that for example you have database view PersonalInformation which returns for you data from for example table Person and DetailedInformation. So in this case for me it's good to have three classes Person, DetailedInformation and PersonInformation which have instance of Person and DetailedInformation class something like public class PersonInformation {public Person Person {get;set;} public DetailedInformation DetailedInfo {get;set;}} – Piotr Czarnecki Jun 05 '13 at 12:23
2

From MSDN Article -

The main benefits of the N-tier/3-tier architectural style are:

  • Maintainability. Because each tier is independent of the other tiers, updates or changes can be carried out without affecting the application as a whole.
  • Scalability. Because tiers are based on the deployment of layers, scaling out an application is reasonably straightforward.
  • Flexibility. Because each tier can be managed or scaled independently, flexibility is increased.
  • Availability. Applications can exploit the modular architecture of enabling systems using easily scalable components, which increases availability.

You have tight coupled layers. Try to make them loose coupled.

To start with, following visual studio solution template may help you out -

Layered Architecture Solution Guidance 2010

Parag Meshram
  • 7,580
  • 8
  • 47
  • 86
  • what u mean saying " tight coupled layers" –  Jun 05 '13 at 10:36
  • you can not change your DAL without making any modifications to BLL. Your DAL is also tightly coupled to underlying database type MS SQL. – Parag Meshram Jun 05 '13 at 10:40
  • Try to use Interfaces (what is call contracts in theoretical world) for interacting with DAL. – Parag Meshram Jun 05 '13 at 10:42
  • @sakirayanoglu - give me a moment i will post it in answer in more detail – Parag Meshram Jun 05 '13 at 10:57
  • could u give me a detail sample how to implement or a link.thank you –  Jun 05 '13 at 10:58
  • what u think about this question ??http://stackoverflow.com/questions/16936761/bll-dal-bo-inserting-data/16937854?noredirect=1#16937854 –  Jun 05 '13 at 10:59
  • link you have provided is example of creating DAL with typed DataSet which has adapter classes which will be used to access underlying database – Parag Meshram Jun 05 '13 at 11:40
  • hiya – Parag Meshram,can u give an example based on this question,how we can implement interfaces our project or a link .thank you so much – sakir Sep 19 '13 at 14:23