473,748 Members | 10,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing Business Objects through nTier Web App

Hi all,

I am hoping that someone with some experience developing nTier apps can give
me some advice here.

I am writing an nTier web app that began with a Data Access Layer (DAL),
Business Logic Layer (BLL) and User Interface Layer (UIL).

The problem I found with this was circular referencing...

My objects would be defined in the BLL, so let's say for example that I want
to instantiate a new BLL.Customer object in the UIL, and then run
Customer.AddCus tomer() which would in turn pass the object into the DAL,
let's call this method DAL.AddCustomer (BLL.Customer myCustomer) which would
insert into the DB.

The problem is that the BLL needs to reference the DAL and the DAL needs to
reference the BLL (to receive the custom business object), hence a circular
referencing error. I understand that I could turn this custom object into
some sort of generic object[] or collection and pass it then, or
alternatively pass the method field values one by one (not practical with
10+ values)

What I did was to create a 4th 'vertical' layer which I called the ORL
(Object Reference Layer), the purpose of which is to allow all other layers
to reference the same objects so they can be passed between themselves
without issues. The drawback is that for this to work properly you need to
have the objects themselves defined in the ORL, but the methods defined
statically in the BLL.

My question is this...

Is this good programming?

Obviously it would be ideal to have the object constructor and instance
methods declared in the same class, but I can't seem to get this to work
effectively any other way.

I would appreciate any advice.

- Stu
Nov 17 '05 #1
25 5060
> The problem is that the BLL needs to reference the DAL and the DAL needs
to
reference the BLL (to receive the custom business object), hence a
circular
referencing error.


That doesn't sound right. The bottom layer shouldn't reference the top
layer. So the DAL should not reference the BLL.

Just like in networking protocols. TCP is built on top of IP. It would
break the layer separation if IP referenced a TCP property.

My advise would be to examine why the DAL references the BLL and redesign
the DAL to remove the reference.

Greetings,
Wessel
Nov 17 '05 #2
Thanks for your reply Wessel.

The reason the DAL needs to reference the BLL is because it need to know
about the object it's being passed.

For example if I have a Customer object in the BLL and I pass it as a
parameter in DAL.UpdateCusto mer(BLL.Custome r myCustomer), the DAL needs to
know what sort of object a 'Customer' is, and so i need to reference the BLL
layer from the DAL layer.

If i didn't do this, i would not be able to pass 'Customer' as a parameter
between layers, i would instead need to either pass the individual
properties one by one, or use another type of object that the DAL already
knows about (ie. object array)

"Wessel Troost" <no*****@like.t he.sun> wrote in message
news:op.sutprqb kf3yrl7@asbel.. .
The problem is that the BLL needs to reference the DAL and the DAL needs
to
reference the BLL (to receive the custom business object), hence a
circular
referencing error.


That doesn't sound right. The bottom layer shouldn't reference the top
layer. So the DAL should not reference the BLL.

Just like in networking protocols. TCP is built on top of IP. It would
break the layer separation if IP referenced a TCP property.

My advise would be to examine why the DAL references the BLL and redesign
the DAL to remove the reference.

Greetings,
Wessel

Nov 17 '05 #3
Hi Stuart,
For example if I have a Customer object in the BLL and I pass it as a
parameter in DAL.UpdateCusto mer(BLL.Custome r myCustomer), the DAL needs
to
know what sort of object a 'Customer' is, and so i need to reference the
BLL
layer from the DAL layer.

Well, so why don't you move the definition of Customer from the BLL to the
DAL? That seems like a proper place to put it in any case.

Good luck,
Wessel
Nov 17 '05 #4
Hi Wessel,

Thanks for the input.

I see what your saying, but i would tend to think it needs to stay the the
BLL.

As i understand it, the purpose of the DAL is simply to seperate the
datasource interactions from the actual business logic of the application.
So for example if i decided to move from SQL2000 to MySql in the future i
would only need to update the DAL, not rewrite the entire thing.

Also, if i was to move the Customer object into the DAL, then i would really
need to move all my other business objects since virtually all of them
interact with a datasource in some way, and obviously if i did that then i
wouldn't have a BLL anymore, the DAL & BLL would merge and it would become a
2 tier app.

The 3 Tier architecture seems to be used a lot, I would think that someone
would have come accross this issue before.

- Stu

"Wessel Troost" <no*****@like.t he.sun> wrote in message
news:op.sutsvjt tf3yrl7@asbel.. .
Hi Stuart,
For example if I have a Customer object in the BLL and I pass it as a
parameter in DAL.UpdateCusto mer(BLL.Custome r myCustomer), the DAL needs
to
know what sort of object a 'Customer' is, and so i need to reference the
BLL
layer from the DAL layer.

Well, so why don't you move the definition of Customer from the BLL to the
DAL? That seems like a proper place to put it in any case.

Good luck,
Wessel

Nov 17 '05 #5
Hi,

I have used a different approach, My "DAL" has no knowledge about the BLL ,
all it cares about is interacting with the DB , it receive a SqlCommand from
the BLL and it execute it, and return the values.

It's in the BLL where each object ( as Customer ) create theirs command and
then use the DAL to have them executed.

This work on my situation cause I know this system will ALWAYS use a SQL DB.

If you want to have more independency it gets complex, you could have an
abstract factory to create the DAL that interact with the especific DB
back-end.

alternative you could create abstract classes/interfaces in a separate
prject, then have both the BLL and the DAL reference it, this way you avoid
the circular references.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Stuart Hilditch" <st************ *@gmail.com> wrote in message
news:Rs******** **********@news-server.bigpond. net.au...
Thanks for your reply Wessel.

The reason the DAL needs to reference the BLL is because it need to know
about the object it's being passed.

For example if I have a Customer object in the BLL and I pass it as a
parameter in DAL.UpdateCusto mer(BLL.Custome r myCustomer), the DAL needs to
know what sort of object a 'Customer' is, and so i need to reference the
BLL layer from the DAL layer.

If i didn't do this, i would not be able to pass 'Customer' as a parameter
between layers, i would instead need to either pass the individual
properties one by one, or use another type of object that the DAL already
knows about (ie. object array)

"Wessel Troost" <no*****@like.t he.sun> wrote in message
news:op.sutprqb kf3yrl7@asbel.. .
The problem is that the BLL needs to reference the DAL and the DAL needs
to
reference the BLL (to receive the custom business object), hence a
circular
referencing error.


That doesn't sound right. The bottom layer shouldn't reference the top
layer. So the DAL should not reference the BLL.

Just like in networking protocols. TCP is built on top of IP. It would
break the layer separation if IP referenced a TCP property.

My advise would be to examine why the DAL references the BLL and redesign
the DAL to remove the reference.

Greetings,
Wessel


Nov 17 '05 #6
Thanks Ignacio,

It's not so much that I think that will ever move from SQL svr, I am really
just trying to enforce a complete seperation of data access and business
logic and I would think that by creating SqlCommands within the BLL you are
getting very close to removing the DAL altogether.

Like i said, I've no real interest in access multiple db's so I think an
abstract factory would be overkill, however the seperate project with
classes that can be referenced by both the DAL and the BLL seems like what i
have already in the form of an ORL (Object Reference Layer).

I'm really just curious to know if this is best practise considering this
scenario? The reason is that by using this technique I can't use instance
methods, so effectively my classes & properties are defined in the ORL and
the methods are defined (statically) in the BLL. It's a bit odd programming
in this way, but it works.

- Stu

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:Ov******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I have used a different approach, My "DAL" has no knowledge about the BLL
, all it cares about is interacting with the DB , it receive a SqlCommand
from the BLL and it execute it, and return the values.

It's in the BLL where each object ( as Customer ) create theirs command
and then use the DAL to have them executed.

This work on my situation cause I know this system will ALWAYS use a SQL
DB.

If you want to have more independency it gets complex, you could have an
abstract factory to create the DAL that interact with the especific DB
back-end.

alternative you could create abstract classes/interfaces in a separate
prject, then have both the BLL and the DAL reference it, this way you
avoid the circular references.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Stuart Hilditch" <st************ *@gmail.com> wrote in message
news:Rs******** **********@news-server.bigpond. net.au...
Thanks for your reply Wessel.

The reason the DAL needs to reference the BLL is because it need to know
about the object it's being passed.

For example if I have a Customer object in the BLL and I pass it as a
parameter in DAL.UpdateCusto mer(BLL.Custome r myCustomer), the DAL needs
to know what sort of object a 'Customer' is, and so i need to reference
the BLL layer from the DAL layer.

If i didn't do this, i would not be able to pass 'Customer' as a
parameter between layers, i would instead need to either pass the
individual properties one by one, or use another type of object that the
DAL already knows about (ie. object array)

"Wessel Troost" <no*****@like.t he.sun> wrote in message
news:op.sutprqb kf3yrl7@asbel.. .
The problem is that the BLL needs to reference the DAL and the DAL
needs to
reference the BLL (to receive the custom business object), hence a
circular
referencing error.

That doesn't sound right. The bottom layer shouldn't reference the top
layer. So the DAL should not reference the BLL.

Just like in networking protocols. TCP is built on top of IP. It would
break the layer separation if IP referenced a TCP property.

My advise would be to examine why the DAL references the BLL and
redesign the DAL to remove the reference.

Greetings,
Wessel



Nov 17 '05 #7
Hi Stewart,
Also, if i was to move the Customer object into the DAL, then i would


Well I know two kinds of DAL, handwritten and generated. Generation
enforces the separation of layers rule; you can't generate objects the
database doesn't know about. So I assume you're using a handwritten DAL.

Usually in such a scenario, the Customer class would correspond to a
database tabled called (something like) Customers. The DAL would then
contain a class named Customer, with optional operations like
UpdateCustomer( ) and the like.

However, you say your Customer class resides in the BLL. So I'm curious:
what does your DAL contain?

Greetings,
Wessel
Nov 17 '05 #8

Typically, a data access tier is meant to encapsulate the access to
persistent storage such that there is no implementation-dependent code
within the BLL. It's often little more than a thin wrapper on a set of
stored procedures. It shouldn't really know anything at all about your
domain model classes.

The problem you've got is where to put the mapping code to connect the
domain model classes to the data access logic. One option is a separate
mapping library which knows about the data access layer, knows about the
domain model, and mediates between them.

http://www.martinfowler.com/eaaCatalog/dataMapper.html

A less clean but simpler solution [simpler for small implementations ,
I've found that a mapping-based architecture simplifies large / complex
systems] is to access the DAL directly from within the domain classes.
So, you write a DAL with methods which take simple parameters and return
DataTables and/or DataSets. The code mapping the data to the object is
then encapsulated within the domain model class, which is nice, but
knows a little too much about the underlying storage medium, which is
not nice.

--
Steve Walker
Nov 17 '05 #9
Hi Wessel,

My Customer class used to reside in the BLL, but in order for the DAL to
access the Customer object I needed to move it into another layer which I
call an Object Reference Layer (ORL).

Now that Customer is in the ORL (think of it as a vertical layer rather than
a traditional horizontal layer) I am able to access the object from every
other layer (UIL, BLL, DAL) and I can pass the object between these layers.

This saves me from declaring the same class multiple times. If I was to
declare the Customer class in the DAL, the although I could access the
object from the BLL, I could not access it from the UIL (User Interface
Layer).

However, using this technique, I cannot use instance methods. Therefore all
of my methods are static, and in the BLL my methods are used for enforcing
business rules as well as passing through to the DAL from the UIL eg.

public static bool BLL.InsertCusto mer(ORL.Custome r myCustomer)
{
return DAL.InsertCusto mer(myCustomer) ;
}

In the DAL, all of my methods are static and they perform InsertCustomer,
UpdateCustomer, DeleteCustomer, etc actions, and they are always called from
the BLL, never directly from the UIL.

- Stu

"Wessel Troost" <no*****@like.t he.sun> wrote in message
news:op.sutznku of3yrl7@asbel.. .
Hi Stewart,
Also, if i was to move the Customer object into the DAL, then i would


Well I know two kinds of DAL, handwritten and generated. Generation
enforces the separation of layers rule; you can't generate objects the
database doesn't know about. So I assume you're using a handwritten DAL.

Usually in such a scenario, the Customer class would correspond to a
database tabled called (something like) Customers. The DAL would then
contain a class named Customer, with optional operations like
UpdateCustomer( ) and the like.

However, you say your Customer class resides in the BLL. So I'm curious:
what does your DAL contain?

Greetings,
Wessel

Nov 17 '05 #10

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

Similar topics

11
3184
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to the Data Access Layer method -or- 2) Pass some kind of a unique id to the Data Access Layer method
3
4756
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing around chunks of data in DataTables/DataSets, simply because that was the format that they were in when the data was taken from the database. Now, I know this maybe a pretty silly question with a standard "it depends" answer, but I'm going to...
4
2578
by: Jack | last post by:
Hi, I have a hashtable that I need to pass around to different Business Objects. My question is it better to pass it and make a locale hashtable variable and set it equal to the passed hashtable or should I pass it and not worry about it? Thanks
3
2684
by: Marc Castrechini | last post by:
First off this is a great reference for passing data between the Data Access and Business Layers: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/Anch_EntDevAppArchPatPrac.asp I use my own classes in the Business layer. I want to keep the Data Access layer from requiring these classes so I tried passing a Datarow between the layers and it seems to work good for me. Constructing the datarow in the Class...
12
5342
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and the windows application. I face the following problem when I send this class to the webservice.
11
2570
by: Peter M. | last post by:
Hi all, I'm currently designing an n-tier application and have some doubts about my design. I have created a Data Access layer which connects to the database (SQL Server) and performs Select, update, delete and inserts. I use dataset objects to pass data to and from the DAL. In my GUI (windows forms), I use databinding to bind controls to a datatable
3
1366
by: waheed azad | last post by:
Hi, I have a been developing an accounting system for a non-profit organization. I had decided to to divide the solution, in three layers, presentation, business layer and database layer. My business layer is composed of objects like Account, Transaction, Voucher etc. And my database layer is composed of objects like AccountDB, TransactionDB, VoucherDB. Now each of my layer is residing in a seperate project under the same solution....
2
2641
by: grawsha2000 | last post by:
Greetings, I am developing this N-tier business app. The problem I'm facing is when I try to pass business objects (employees, dept..etc) from business tier to data tier,i.e., the add method in the data tier expects business object from the business tier, I get an error saying: Can not covert businesslayer.emp to businesslayer.emp
2
2471
by: Andrus | last post by:
Winforms UI assembly has static FormManager.FormCreator method which creates forms taking entity as parameter. I need to pass this method to business objects in business assembly so that business methods can also create forms but does not have reference to UI assembly. I tried code below but got compile errows shown in comments. How to fix ? Andrus.
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.