473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

N-Tier Structure question

Hello,

I want to create business and data access layer for my website. I am
not sure what the right way to go is, I could use a code-generation
tool, but want to understand a bit more about design.

Basically I have my DAL, BOL, & Website project....

in DAL I have the class OrderDB with a method called List()
which returns a collection object called OrderList which is
specified in the BOL project, where I have OrderList and Order
classes.

In DAL I have a reference to BOL, and in the Website I have a reference
to BOL & DAL. I fill my datagrid much like this...

OrderDB odb = new OrderDB();
OrderList ol = odb.List();
DataGrid.DataSource = ol;
DataGrid.DataBind();

However I could actually add another class to the BOL project, call
Orders which calls the OrderDB.List() as a static method returning a
IDataReader object (I am using Enterprise Application Blocks), then
there I iterate thru it and load my OrderList object and send it to the
UI tier.... so it would go

Orders ors = new Orders();
OrderList ol = ors.GetList();
DataGrid.DataSource = ol; etc..etc...

in this case I have a reference to DAL in BOL, and a reference in to
BOL in Website....this seems to be a better n-tier structure in terms
of referencing and passing thru the layers but does not seem to be the
case here
http://msdn.microsoft.com/library/de...tml/BOAGag.asp

Any thoughts

Nov 19 '05 #1
8 1028
Hi yurps ,

OrderDB odb = new OrderDB();
OrderList ol = odb.List();
DataGrid.DataSource = ol;
DataGrid.DataBind();

This snippet seems to put too much work on UI. I mean the UI has to
know lot of stuff he
has to know how the DAL works and How the BOL works....Definetly not a
preferred way.
Second snippet just wanted to know why the Orderlist

Orders ors = new Orders();
OrderList ol = ors.GetList();
DataGrid.DataSource = ol; etc..etc...
Simple the orders class calls the Orderdb and iterates and load the
collection
(Orders is inherited from collection base)

Orders ors = new Orders();
ors.GetList();
DataGrid.DataSource = ors;
Shivprasad Koirala
C# , VB.NET , SQL SERVER , ASP.NET Interview Questions
http://www.geocities.com/dotnetinterviews/

Nov 19 '05 #2
Over the past few years I have leaned more towards a seperation of the
UI, Business and DAL. I have always clumped the DAL and Business
Objects together. I have also tried to cut down on what the UI has to
do.

I would suggest you let the UI know as little as possible about the BO
and the DAL. In fact, I would not let the UI even know there is a DAL.
Here's an example of a recent project:

Classes:
Users.DAL
Users
User
UserController
WebApp

The WebApp only ever knows about the UserController. The UserController
only knows about the Users. The Users knows about the User and
Users.DAL classes.

This keeps you code seperated enough that if you decide to do something
differently in your Business layer, that it would be pretty much plug
and play. Say for example you wanted to populate a treeview control
with a list of users nested based on company hierarchy:

UI:
UserController.GetCompanyList(treeview, ConnectionObject, Language);

that's all the UI has to know about. Now in your controller you are
doing something like this:

public static void GetCompanyList(TreeView tree, ConnectionObject conn,
string Language)
{
Users users = new Users(ConnectionObject, Language);
foreach(User user in Users)
{
AddNode(user, currnode);
//add your node to your tree
}
}
public static void AddNode(User user, TreeNode node)
{
foreach(User childuser in user.Subordinates)
{
// ....add node here
if(childuser.Subordinates!=null)
AddNode(user, currnode);
}

}
public class Users
{
public Users(ConnectionObject conn, string Language)
{
DataSet ds = Users.DAL.GetList(conn, Language)
foreach(DataRow dr in ds.Tables[0].Rows)
{
User user = new User();
user.FirstName = ....
this.Add(user);
}
ds.Dispose();
}
}

But by creating the abstraction here of the UserController if you ever
wanted to change what gets displayed to the UI, it's a simple change at
the UserController layer. Or, if you wanted to completely change how
the Users object was filled, say you wanted to get it from XML instead
of a db, then you only have one place to change it.

Nov 19 '05 #3
A Data Access Layer should be agnostic of a Business layer:
in DAL I have the class OrderDB with a method called List()
which returns a collection object called OrderList which is
specified in the BOL project, where I have OrderList and Order
classes.
This OrderDB class sounds more like a Business object than a DAL object.
What sort of Database object is an "Order?"
In DAL I have a reference to BOL
Again, the DAL should be Business-agnostic. It should have no knowledge of
upper tiers.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Paranoia is just a state of mind.

"yurps" <yu***@yahoo.co.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com... Hello,

I want to create business and data access layer for my website. I am
not sure what the right way to go is, I could use a code-generation
tool, but want to understand a bit more about design.

Basically I have my DAL, BOL, & Website project....

in DAL I have the class OrderDB with a method called List()
which returns a collection object called OrderList which is
specified in the BOL project, where I have OrderList and Order
classes.

In DAL I have a reference to BOL, and in the Website I have a reference
to BOL & DAL. I fill my datagrid much like this...

OrderDB odb = new OrderDB();
OrderList ol = odb.List();
DataGrid.DataSource = ol;
DataGrid.DataBind();

However I could actually add another class to the BOL project, call
Orders which calls the OrderDB.List() as a static method returning a
IDataReader object (I am using Enterprise Application Blocks), then
there I iterate thru it and load my OrderList object and send it to the
UI tier.... so it would go

Orders ors = new Orders();
OrderList ol = ors.GetList();
DataGrid.DataSource = ol; etc..etc...

in this case I have a reference to DAL in BOL, and a reference in to
BOL in Website....this seems to be a better n-tier structure in terms
of referencing and passing thru the layers but does not seem to be the
case here
http://msdn.microsoft.com/library/de...tml/BOAGag.asp

Any thoughts

Nov 19 '05 #4
As others have pointed out, you have your DAL referring to your Business
objects. That's pretty much backward. The Business objects can refer to
the DAL for persistence, but the DAL itself knows nothing about the business
rules... it just knows how to persist.

I have a novel idea: reuse. Why not just reuse the DAL that is built in to
the Enterprise Library? Then you won't have to write one!
(See my blog:
http://blogs.msdn.com/nickmalik/arch...01/446395.aspx )

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"yurps" <yu***@yahoo.co.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello,

I want to create business and data access layer for my website. I am
not sure what the right way to go is, I could use a code-generation
tool, but want to understand a bit more about design.

Basically I have my DAL, BOL, & Website project....

in DAL I have the class OrderDB with a method called List()
which returns a collection object called OrderList which is
specified in the BOL project, where I have OrderList and Order
classes.

In DAL I have a reference to BOL, and in the Website I have a reference
to BOL & DAL. I fill my datagrid much like this...

OrderDB odb = new OrderDB();
OrderList ol = odb.List();
DataGrid.DataSource = ol;
DataGrid.DataBind();

However I could actually add another class to the BOL project, call
Orders which calls the OrderDB.List() as a static method returning a
IDataReader object (I am using Enterprise Application Blocks), then
there I iterate thru it and load my OrderList object and send it to the
UI tier.... so it would go

Orders ors = new Orders();
OrderList ol = ors.GetList();
DataGrid.DataSource = ol; etc..etc...

in this case I have a reference to DAL in BOL, and a reference in to
BOL in Website....this seems to be a better n-tier structure in terms
of referencing and passing thru the layers but does not seem to be the
case here
http://msdn.microsoft.com/library/de...tml/BOAGag.asp

Any thoughts

Nov 19 '05 #5
Thanks for all the replies, I am now confident about what I originally
thought was the case. I guess the link I posted put me off track a
bit.

shiv_koir - the Orders class is not a collection rather it would be
better described as a OrdersController or OrdersManager which has a
static method returning an OrdersCollection....however I do think I can
add a method to my OrdersCollection which will fill it up, and thus
bypass the Controller class.

brian.fairch - I do like you idea of only making this object visible to
the WebUI, but I think it will need a reference to the System.Web.UI
namespace where the rest of the BizObject will not. Are you suggesting
passing a ConnectionObject into the UserController Business Object? I
thought that the DAL would take care of this.

Nick Malik - You are right, in a way my DAL is just a facade to the MS
Application Blocks, I just wrap the calls so they only access the our
apps sprocs and return DataReaders to the BizObject to fill the
TypedCollections or single object instances. This was what made my
initial decision to use them, as I had seen some other code which
allowed DataReaders to be passed between tiers I wanted good framework
to do this like this block provides.
Thanks for the link, basically I have a working website, I am
refactoring the app now as we went quickly from prototype to release so
there wasn't time originally to think about scalable design. More
organisations like developers to have knowledge of the Application
Blocks, so I thought it best to incorporate them even though I have my
own ExceptionHandling & Cryptography implementations. Additionally I
would like to put some elements of Lhoka's CLSA.Net into this so we can
scale out with the component hosted on a separate machine.

Nov 19 '05 #6
I run an app where I need the same object to connect to different db's
of the same structure. That's the only reason I would pass along a
connection object.

Nov 19 '05 #7
A tad confused here. I'm looking to provide routines that return a
typed dataset or collection.
Example, right now I have User class, with nothing about data access in
it.
I also have User collection.
I have UI with nothing about data access, only reference to User
objects.

I have a routine called GetUsers that returns an User collection (and
thus knows about Users).

So this is ok so far? I was referring to GetUsers as part of my DAL.
Is it just the semantics that are incorrect, or does this point to a
design flaw?

Nov 19 '05 #8
There is some semantics here. The important part is that the business layer
doesn't know how an item is stored, and the Data layer doesn't know how an
item is used. GetUsers can be part of your DAL, as long as it doesn't refer
to a business object. The moment it refers to a business object, it is part
of your business layer. Since it pretty much has to refer to the business
objects, it is part of what I would call a "mapping layer" that maps
Relational to OO structures. The key is not to do any work other than
mapping in this layer.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
<jh*****@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
A tad confused here. I'm looking to provide routines that return a
typed dataset or collection.
Example, right now I have User class, with nothing about data access in
it.
I also have User collection.
I have UI with nothing about data access, only reference to User
objects.

I have a routine called GetUsers that returns an User collection (and
thus knows about Users).

So this is ok so far? I was referring to GetUsers as part of my DAL.
Is it just the semantics that are incorrect, or does this point to a
design flaw?

Nov 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: basement_addict | last post by:
First off I am new to xmlrpc.I am working on a project that requires me to return this structure. <?xml version="1.0"?> <methodResponse> <params> <param> <struct> <member> <name>files</name>
1
by: drinc2much | last post by:
Let me just start out by saying that I am a Java webapp developer. I was pulled into rebuilding our intranet site. I have limited experience with what is the best method for structuring an intranet...
0
by: Duncan | last post by:
It is on WINCE. But should not matter. I am binding a datagrid to a ArrayList using the datasource property of the datagrid. ArrayList will contain data structures. The data structure contains all...
5
by: Bob Weiner | last post by:
I'm new to C#. What is the best (in terms of programmability and use) data structure to use to maintain an array of information with containing 3 fields of differing types. For instance:...
16
by: Duncan Mole | last post by:
Hi, This is probably an easy one but it iy first bit of p/invoke. I am trying to use the following C struct in a call: typedef struct { BYTE SRB_Cmd; BYTE SRB_Status, BYTE ...
4
by: Jeff Johnson [MVP: VB] | last post by:
Pardon the crosspost, but I couldn't find a generic .NET group for VS.NET. I was wondering about the directory structure that the IDE creates when making a project. What's the point of the bin...
2
by: Peter Lux | last post by:
I have a structure called Stitch that has an x,y coordinate, a maincolor mc and a secondary color, sc. I want to render these @ the x,y coordinate. I've already done that without it being in a...
4
by: ibiza | last post by:
Hi SQL gurus, I have a table structure question. I will have a table 'Models' that has one to many 'incomes' and one to many 'costs'. These 2 entities have exactly the same structure, which is...
3
by: Michael | last post by:
Hi, I have had a look in the FAQ but cannot see anything related, of course that doesn't mean it's not there. In any case: I have the following: void function(){ struct tm *time2;
2
by: K Viltersten | last post by:
Suppose there is the following class structure. class S {...} class A : S {...} class B : S {...} class A1 : A {void m(){...}} class B1 : B {void m(){...}} class B2 : B {...} Just to clarify...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.