PC Review


Reply
Thread Tools Rate Thread

Business Layer - Data Layer

 
 
David Gouge
Guest
Posts: n/a
 
      20th Jul 2005
Hi all,

I hope this is a suitable group for this question. Feel free to push me
off to the correct one if not.

Basically i have been developing windows applications using Visual
Foxpro for about 5 years for a small software house and we will be
shortly moving to a .net (C#) solution.

Within our VFP applications there are no distinct application layers
whatsoever. Business logic, data access / manipulation and GUI code is
all lumped together on forms and program files. With our move to .net I
would like to implement more of a 3 teir architecture with the UI,
Business Logic and Data Access / Manipulation all separated out.

I understand completely the theory behind this, but am struggling
somewhat to grasp the practical details. If, for example, I have a
Client object in my Business layer, what would i need to do do access /
update data based on the theory that the Business layer does not have
any sql statements etc in it? Pass datasets between the two layers? Or
xml / web services?

If someone could give me a point in the right direction or let me know
of some good resources / books i would be most grateful.

Best Wishes,

David Gouge
 
Reply With Quote
 
 
 
 
Ziga Jakhel
Guest
Posts: n/a
 
      20th Jul 2005
Normally you pass some sort of a data object between the layers. This can be
either a custom class, a dataset, or whatever else you may desire. Just make
sure the object is serializable if you wish to pass it between processes.
Normally you would choose to keep the dataobjects in a separate dll you can
reference in each of the application layers.

How you separate the layers physically is another question, but the logical
separation is the basic prerequisite for physical separation.
You can either keep the layers together physically, simply instantiating
objects from different layers in the same application (application domain),
or you can run the layers in different processes (application domains -
applications, services, webservices,...), separating them with remoting,
webservice, msmq, or other facades (thin interop layers that facilitate
communication).

What level of physical separation you choose depends more or less on the
solution design requirements - security, system, network, performance, etc.
requirements that have to be taken into account - and, of course, personal
preference. There really is no general rule that would fit every approach.
Basically what you should remember at all time is to create your components
statelessly... keeping state is bad, especially with physical separation of
the layers, and designing for asynchronisity is a good approach for boosting
performance.

I would also suggest you look into MessageQueuing and
System.EnterpriseServices a bit... they are an often overlooked part of a
windows box which can solve quite a few problems regarding isolation of
processes and running different components in separate application domains
with different security & trust levels.

Otherwise, recommended reading would be found inthe Microsoft's Patterns &
Practices library, especially in the architecture center.
(http://msdn.microsoft.com/architecture/)

The specific topic of passing data through tiers is dealt with in the
"Designing Data Tier Components and Passing Data Through Tiers" guide, found
at
http://msdn.microsoft.com/library/de...tml/BOAGag.asp

I hope this helps you further.

Regards,

Ziga Jakhel
MCSD.NET
ziga.jakhel(a)rrc.si

"David Gouge" <(E-Mail Removed)> wrote in message
news:eeZA$(E-Mail Removed)...
> Hi all,
>
> I hope this is a suitable group for this question. Feel free to push me
> off to the correct one if not.
>
> Basically i have been developing windows applications using Visual Foxpro
> for about 5 years for a small software house and we will be shortly moving
> to a .net (C#) solution.
>
> Within our VFP applications there are no distinct application layers
> whatsoever. Business logic, data access / manipulation and GUI code is
> all lumped together on forms and program files. With our move to .net I
> would like to implement more of a 3 teir architecture with the UI,
> Business Logic and Data Access / Manipulation all separated out.
>
> I understand completely the theory behind this, but am struggling somewhat
> to grasp the practical details. If, for example, I have a Client object
> in my Business layer, what would i need to do do access / update data
> based on the theory that the Business layer does not have any sql
> statements etc in it? Pass datasets between the two layers? Or xml / web
> services?
>
> If someone could give me a point in the right direction or let me know of
> some good resources / books i would be most grateful.
>
> Best Wishes,
>
> David Gouge



 
Reply With Quote
 
David Gouge
Guest
Posts: n/a
 
      21st Jul 2005
Ziga Jakhel wrote:
> Normally you pass some sort of a data object between the layers. This can be
> either a custom class, a dataset, or whatever else you may desire. Just make
> sure the object is serializable if you wish to pass it between processes.
> Normally you would choose to keep the dataobjects in a separate dll you can
> reference in each of the application layers.
>
> How you separate the layers physically is another question, but the logical
> separation is the basic prerequisite for physical separation.
> You can either keep the layers together physically, simply instantiating
> objects from different layers in the same application (application domain),
> or you can run the layers in different processes (application domains -
> applications, services, webservices,...), separating them with remoting,
> webservice, msmq, or other facades (thin interop layers that facilitate
> communication).
>
> What level of physical separation you choose depends more or less on the
> solution design requirements - security, system, network, performance, etc.
> requirements that have to be taken into account - and, of course, personal
> preference. There really is no general rule that would fit every approach.
> Basically what you should remember at all time is to create your components
> statelessly... keeping state is bad, especially with physical separation of
> the layers, and designing for asynchronisity is a good approach for boosting
> performance.
>
> I would also suggest you look into MessageQueuing and
> System.EnterpriseServices a bit... they are an often overlooked part of a
> windows box which can solve quite a few problems regarding isolation of
> processes and running different components in separate application domains
> with different security & trust levels.
>
> Otherwise, recommended reading would be found inthe Microsoft's Patterns &
> Practices library, especially in the architecture center.
> (http://msdn.microsoft.com/architecture/)
>
> The specific topic of passing data through tiers is dealt with in the
> "Designing Data Tier Components and Passing Data Through Tiers" guide, found
> at
> http://msdn.microsoft.com/library/de...tml/BOAGag.asp
>
> I hope this helps you further.
>
> Regards,
>
> Ziga Jakhel
> MCSD.NET
> ziga.jakhel(a)rrc.si



Thank you so much for your concise reply. I'll be sure to have a look
at those articles you suggested. As I mentioned, moving from our 'one
big fat messy layer' in our vfp app to this more structured approach has
been giving me headaches, but your reply has helped a lot.

Thanks again,

Dave
 
Reply With Quote
 
David Gouge
Guest
Posts: n/a
 
      21st Jul 2005
Ziga Jakhel wrote:
> Normally you pass some sort of a data object between the layers. This can be
> either a custom class, a dataset, or whatever else you may desire. Just make
> sure the object is serializable if you wish to pass it between processes.
> Normally you would choose to keep the dataobjects in a separate dll you can
> reference in each of the application layers.
>


Hi Ziga,

Again, thanks for the reply. Just one more detailled question if i may.

If I have my Client object in my business logic layer that has a method
LoadClientDetails(int ClientUnique) to fill the client object with data
from the underlying database, how would that be realised? For example,
before i understood the distinction between the layers i would have put
in the Client.LoadClientDetails method code to create a db connection
object, run some sql based on the ClientUnique and then use the
datareader (or whatever) to populate the object's fields.

Now I understand that business objects (strictly) must not have things
such as connections / sql inside them, so to get the client data i am
interested in, would i also need a corresponding method on an object in
the data layer that returns the client dataset? So in effect a call to
Client.LoadClientDetails() would result in the Client object making a
call to SomeDataObject.LoadClientDetails().

Or would the datalayer be more generic, and if so, the Client object
would then need to be specifying table / fields etc for the data layer
to return.

My head hurts.

Thanks Again,

Dave
 
Reply With Quote
 
Ziga Jakhel
Guest
Posts: n/a
 
      21st Jul 2005
Hi, David!

An interesting question that demonstrates a common problem with multi-tier
solutions - plenty of pass-through methods, as you should not jump layers.

Let's assume your Client object is primarily a data carrier.

So, when you want to fill it with data, you:

1) Pass it to the BLL and call some FillClientWithData method there
2) The BLL method in turn passes the Client object down to the DAL, where it
actually gets filled
- or-
2a) The BLL gets data from the DAL through some other carriers (like
disconnected datasets) and transfers it into the Client object. (this could
also be done in a multi-layered DAL)

The call would be something like MyBLLObject.FillClientWithData(Client)
and the BLL object would go MyDALObject.FillClientWithData(Client), so yes,
you need appropriate methods in the BLL and DAL.

In this scenarion BLL actually does nothing "of value" by itself, but simply
pass the object back and forth, in fact acting as a facade for the DAL.
If you have a plain-vanilla data-entry or data-edit scenario, the BLL is
normall comprised mainly of DAL pass-through methods. The Business Logic
comes into play when you add data validation, lookups, data aggregation from
different sources, actual computational logic, etc,. into the BLL.

When developing a client component I usually compose it from an instance of
a data carrier class that is accessible from all layers and gets
transferred between the layers, and it's own logic that uses and manipulates
the data. So the Client, for instance, calls the BLL.FillMeWithData() method
and passes/recieves a DataCarrier object that it then processes. The BLL in
turn then calls the DAL, which goes to the DB, and so on. Objects on each
layer only know object from the next layer, that's how it should be. Only
common stuff such as data carriers, enumerators, etc. are usually
universally known and deployed in shared dlls.

Regards,

Ziga

"David Gouge" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Ziga Jakhel wrote:
>> Normally you pass some sort of a data object between the layers. This can
>> be either a custom class, a dataset, or whatever else you may desire.
>> Just make sure the object is serializable if you wish to pass it between
>> processes. Normally you would choose to keep the dataobjects in a
>> separate dll you can reference in each of the application layers.
>>

>
> Hi Ziga,
>
> Again, thanks for the reply. Just one more detailled question if i may.
>
> If I have my Client object in my business logic layer that has a method
> LoadClientDetails(int ClientUnique) to fill the client object with data
> from the underlying database, how would that be realised? For example,
> before i understood the distinction between the layers i would have put in
> the Client.LoadClientDetails method code to create a db connection object,
> run some sql based on the ClientUnique and then use the datareader (or
> whatever) to populate the object's fields.
>
> Now I understand that business objects (strictly) must not have things
> such as connections / sql inside them, so to get the client data i am
> interested in, would i also need a corresponding method on an object in
> the data layer that returns the client dataset? So in effect a call to
> Client.LoadClientDetails() would result in the Client object making a call
> to SomeDataObject.LoadClientDetails().
>
> Or would the datalayer be more generic, and if so, the Client object would
> then need to be specifying table / fields etc for the data layer to
> return.
>
> My head hurts.
>
> Thanks Again,
>
> Dave



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
business layer, data access layer , presentation layer for asp.net using C#.net Dhananjay Microsoft VB .NET 6 20th Dec 2006 02:16 AM
business layer, data access layer , presentation layer for asp.net using C#.net Dhananjay Microsoft C# .NET 2 19th Dec 2006 09:23 AM
business layer, data access layer , presentation layer for asp.net using C#.net Dhananjay Microsoft ASP .NET 1 18th Dec 2006 11:35 PM
How to distingusih Business Layer and Data Access Layer requirements pratham Microsoft C# .NET 4 31st Aug 2006 07:18 AM
Business Layer, Data Layer, Speed Issues, Classes, and all that et Microsoft ASP .NET 2 6th Mar 2006 02:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:27 PM.