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.
DA Objects should represent your database schema in some way and should be strictly binded to the Database activity.
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.
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.