HI everyone,
I think i am on the right path but if someone could confirm it, that
would be great.
In my business Layer i have my business object, for this example,
called User.
User has about 50 properties.
To save the user object in my business layer i call the factory and
pass in the object
Dim uf as new userFactory
Dim u as user
uf.save(u)
Now because the DAL and business layer shouldnt care about eachother, i
dont want to pass in a business object into my DAL, so at the moment i
pass in each property as a parameter to my save function in my DAL, is
this right??
'Save function in DAL
Function Save(userid as integer, firstname as string, lastname as
string, ............)
'Save function in BL
Function Save (u as user)
dim dal as new dataservice
dal.save(u.id, u.firstname, u.lastname, ..........)
End Function
Does this make sense? Hopefully i am right, but would like to know
what approach everyone takes. Thanks 10 1390
Sorry if that didnt make sense, but i wondered if the DAL save method
should be
Function Save (id, firstname, lastname)
OR
Function Save(tr As TableRow)
For some reason, i think that it should be the second one, as that
would completely separate the DAL and BOL.
Someone please put me out of my misery! lol
Hi,
Nemisis wrote:
HI everyone,
I think i am on the right path but if someone could confirm it, that
would be great.
In my business Layer i have my business object, for this example,
called User.
User has about 50 properties.
To save the user object in my business layer i call the factory and
pass in the object
Dim uf as new userFactory
Dim u as user
uf.save(u)
Now because the DAL and business layer shouldnt care about eachother, i
dont want to pass in a business object into my DAL, so at the moment i
pass in each property as a parameter to my save function in my DAL, is
this right??
'Save function in DAL
Function Save(userid as integer, firstname as string, lastname as
string, ............)
'Save function in BL
Function Save (u as user)
dim dal as new dataservice
dal.save(u.id, u.firstname, u.lastname, ..........)
End Function
Does this make sense? Hopefully i am right, but would like to know
what approach everyone takes. Thanks
That's one possibility. But even then, the BLL has to know something
about the DAL, it must know the signature of the method Save and the
parameters. If the method's signature changes, then you must modify the BLL.
A more OO approach would be to define an interface in the DAL specifying
which properties a IUser must implement. The BLL then implements the
interface in its own User class. Then the DAL Save method is:
public void Save( IUser user )
{
...
}
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
So it would be better if i wrote a function in the BOL, that converts
the business object to a Data Row, then passed in the datarow into the
Save function within the DAL?
That way the BOL, only needs to know that it needs to pass in a
datarow, which is a generic object??
>>A more OO approach would be to define an interface in the DAL specifying which properties a IUser must implement. The BLL then implements the interface in its own User class. Then the DAL Save method is:
Can you give me a lil more detail about this? I am new to .NET 2.0 so
i am picking up things as i go along. Does the above involve
referencing a business object in the DAL? Isnt that what i am trying
to avoid?
Nemisis wrote:
Sorry if that didnt make sense, but i wondered if the DAL save method
should be
Function Save (id, firstname, lastname)
OR
Function Save(tr As TableRow)
For some reason, i think that it should be the second one, as that
would completely separate the DAL and BOL.
Someone please put me out of my misery! lol
BANG! You're dead. ;)
Hi,
Nemisis wrote:
So it would be better if i wrote a function in the BOL, that converts
the business object to a Data Row, then passed in the datarow into the
Save function within the DAL?
That way the BOL, only needs to know that it needs to pass in a
datarow, which is a generic object??
I don't really like that approach, because it forces your BOL (business
object layer) (what I called BLL before, Business logic layer) to know
that it's handling with a Database oriented store. It makes you add a
"using" statement more in your code file, if you want.
On the other hand, if you define an interface (this is like an abstract
class) in the DAL, then the BOL must only know that interface's
definition, nothing else. For the BOL, it doesn't matter if the data are
saved in a Database, a XML file, or anything else. You could easily swap
the DAL with another implementation without having to change your BOL code.
>>A more OO approach would be to define an interface in the DAL specifying which properties a IUser must implement. The BLL then implements the interface in its own User class. Then the DAL Save method is:
Can you give me a lil more detail about this? I am new to .NET 2.0 so
i am picking up things as i go along. Does the above involve
referencing a business object in the DAL? Isnt that what i am trying
to avoid?
No, the DAL defines an interface, for example:
public interface IUser
{
public string Name
{
get;
}
}
This specifies that the implementation of IUser must define a "getter"
property named "Name". This is a contract between the DAL and whoever
wants to use the "Save" method.
The save method becomes:
public void Save( IUser user )
{
...
myName = user.Name;
}
Since IUser is known, the DAL knows that it will have a "Name" property.
Then, the BOL accepts the contract by implementing the following:
public class MyUser : IUser
{
public override string Name
{
get
{
return m_Name;
}
}
}
and then:
MyUser user = new MyUser( "USER1" );
DAL.Save( user );
Note that the call to the Save method is successful, because the "user"
variable is of type MyUser, but also IUser. It's polymorphismus, the
same object has two "shapes". It fulfills the contract.
Note however that full OO is not always the best way, especially when it
comes to efficiency and speed.
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
The business layer is always going to have to know something about the data
layer, just as the UI layer must know something about the business layer. It
is the data layer which should not need to know anything about the business
layer (so you can use it in multiple solutions). The business layer must
know the data layers API in order to use it.
Therefore, the data layer function should take raw data and be able to
perform any database operation with it, without knowing what the data is.
That is, your data layer should contain abstract data functionality that is
not specific to any database or data store, and present a uniform API to any
client application.
Here's an example from our in-house data class library:
public static DataTable GetDataTable(st ring query, string tableName,
string connectionStrin g)
{
SqlConnection conn = null;
SqlDataAdapter adapter = null;
DataTable table = new DataTable();
try
{
conn = new SqlConnection(c onnectionstring );
adapter = new SqlDataAdapter( query, conn);
adapter.Fill(ta ble);
if (tableName != "") table.TableName = tableName;
return table;
}
catch (Exception ex)
{
Utilities.Handl eError(ex);
throw new DataException(" Error fetching DataTable", query, cstring, ex);
}
finally
{
if (conn != null) conn.Dispose();
if (adapter != null) adapter.Dispose ();
}
}
This method returns a DataTable, but knows nothing about the table, the
data, or the database being used. The business layer knows the signature of
this method, and can call it whenever it needs a DataTable of data fetched
from its data store.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
It takes a tough man to make a tender chicken salad.
"Nemisis" <da*********@ho tmail.comwrote in message
news:11******** *************@m 79g2000cwm.goog legroups.com...
So it would be better if i wrote a function in the BOL, that converts
the business object to a Data Row, then passed in the datarow into the
Save function within the DAL?
That way the BOL, only needs to know that it needs to pass in a
datarow, which is a generic object??
>>>A more OO approach would be to define an interface in the DAL specifying which properties a IUser must implement. The BLL then implements the interface in its own User class. Then the DAL Save method is:
Can you give me a lil more detail about this? I am new to .NET 2.0 so
i am picking up things as i go along. Does the above involve
referencing a business object in the DAL? Isnt that what i am trying
to avoid?
Kevin Spencer wrote:
The business layer is always going to have to know something about the data
layer, just as the UI layer must know something about the business layer. It
is the data layer which should not need to know anything about the business
layer (so you can use it in multiple solutions). The business layer must
know the data layers API in order to use it.
Therefore, the data layer function should take raw data and be able to
perform any database operation with it, without knowing what the data is.
That is, your data layer should contain abstract data functionality that is
not specific to any database or data store, and present a uniform API to any
client application.
Here's an example from our in-house data class library:
public static DataTable GetDataTable(st ring query, string tableName,
string connectionStrin g)
{
SqlConnection conn = null;
SqlDataAdapter adapter = null;
DataTable table = new DataTable();
try
{
conn = new SqlConnection(c onnectionstring );
adapter = new SqlDataAdapter( query, conn);
adapter.Fill(ta ble);
if (tableName != "") table.TableName = tableName;
return table;
}
catch (Exception ex)
{
Utilities.Handl eError(ex);
throw new DataException(" Error fetching DataTable", query, cstring, ex);
}
finally
{
if (conn != null) conn.Dispose();
if (adapter != null) adapter.Dispose ();
}
}
This method returns a DataTable, but knows nothing about the table, the
data, or the database being used. The business layer knows the signature of
this method, and can call it whenever it needs a DataTable of data fetched
from its data store.
Kevin,
I am confident about the load methods as i load all my data to the BLL
using datasets, but it is more on saving methods from the BLL to DAL.
Can you explain a lil more on this?
I would like to know whether the DAL save method, should either accept
a DataRow (IDataRow), or a series of parameters, thus.
Save(tr as TableRow)
Or
Save(id as integer, name as string, ref as string, ............)
At current i am doing it the second way, but am feeling that maybe i
should be doing it the first way. Any views?
The second method you posted depends upon knowing what fields are in the
table, what table you're updating, and what the database used is. Therefore,
it's not a good Data Layer method. It can only be used with the Business
layer for that project. You want to create generic functions in the Data
layer that perform database operations only. For example, there is no
database operation called "Save." Database operations include things like
SELECT, UPDATE, DELETE, CREATE TABLE, etc. In the case of "Save" you're
talking about doing an UPDATE.
Now, if you want to have a "Save" method in your business class that uses a
generic UPDATE method in your Data layer, that's fine.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
It takes a tough man to make a tender chicken salad.
"Nemisis" <da*********@ho tmail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
>
Kevin Spencer wrote:
>The business layer is always going to have to know something about the data layer, just as the UI layer must know something about the business layer. It is the data layer which should not need to know anything about the business layer (so you can use it in multiple solutions). The business layer must know the data layers API in order to use it.
Therefore, the data layer function should take raw data and be able to perform any database operation with it, without knowing what the data is. That is, your data layer should contain abstract data functionality that is not specific to any database or data store, and present a uniform API to any client application.
Here's an example from our in-house data class library:
public static DataTable GetDataTable(st ring query, string tableName, string connectionStrin g) { SqlConnection conn = null; SqlDataAdapter adapter = null; DataTable table = new DataTable();
try { conn = new SqlConnection(c onnectionstring ); adapter = new SqlDataAdapter( query, conn); adapter.Fill(ta ble); if (tableName != "") table.TableName = tableName; return table; } catch (Exception ex) { Utilities.Handl eError(ex); throw new DataException(" Error fetching DataTable", query, cstring, ex); } finally { if (conn != null) conn.Dispose(); if (adapter != null) adapter.Dispose (); } }
This method returns a DataTable, but knows nothing about the table, the data, or the database being used. The business layer knows the signature of this method, and can call it whenever it needs a DataTable of data fetched from its data store.
Kevin,
I am confident about the load methods as i load all my data to the BLL
using datasets, but it is more on saving methods from the BLL to DAL.
Can you explain a lil more on this?
I would like to know whether the DAL save method, should either accept
a DataRow (IDataRow), or a series of parameters, thus.
Save(tr as TableRow)
Or
Save(id as integer, name as string, ref as string, ............)
At current i am doing it the second way, but am feeling that maybe i
should be doing it the first way. Any views?
Kevin Spencer wrote:
The second method you posted depends upon knowing what fields are in the
table, what table you're updating, and what the database used is. Therefore,
it's not a good Data Layer method. It can only be used with the Business
layer for that project. You want to create generic functions in the Data
layer that perform database operations only. For example, there is no
database operation called "Save." Database operations include things like
SELECT, UPDATE, DELETE, CREATE TABLE, etc. In the case of "Save" you're
talking about doing an UPDATE.
Now, if you want to have a "Save" method in your business class that uses a
generic UPDATE method in your Data layer, that's fine.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
It takes a tough man to make a tender chicken salad.
"Nemisis" <da*********@ho tmail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Kevin Spencer wrote:
The business layer is always going to have to know something about the
data
layer, just as the UI layer must know something about the business layer.
It
is the data layer which should not need to know anything about the
business
layer (so you can use it in multiple solutions). The business layer must
know the data layers API in order to use it.
Therefore, the data layer function should take raw data and be able to
perform any database operation with it, without knowing what the data is.
That is, your data layer should contain abstract data functionality that
is
not specific to any database or data store, and present a uniform API to
any
client application.
Here's an example from our in-house data class library:
public static DataTable GetDataTable(st ring query, string tableName,
string connectionStrin g)
{
SqlConnection conn = null;
SqlDataAdapter adapter = null;
DataTable table = new DataTable();
try
{
conn = new SqlConnection(c onnectionstring );
adapter = new SqlDataAdapter( query, conn);
adapter.Fill(ta ble);
if (tableName != "") table.TableName = tableName;
return table;
}
catch (Exception ex)
{
Utilities.Handl eError(ex);
throw new DataException(" Error fetching DataTable", query, cstring,
ex);
}
finally
{
if (conn != null) conn.Dispose();
if (adapter != null) adapter.Dispose ();
}
}
This method returns a DataTable, but knows nothing about the table, the
data, or the database being used. The business layer knows the signature
of
this method, and can call it whenever it needs a DataTable of data
fetched
from its data store.
Kevin,
I am confident about the load methods as i load all my data to the BLL
using datasets, but it is more on saving methods from the BLL to DAL.
Can you explain a lil more on this?
I would like to know whether the DAL save method, should either accept
a DataRow (IDataRow), or a series of parameters, thus.
Save(tr as TableRow)
Or
Save(id as integer, name as string, ref as string, ............)
At current i am doing it the second way, but am feeling that maybe i
should be doing it the first way. Any views?
Yes kevin, i understand that, my save method is actually called Update
(sorry for the confusion), but what you are saying is that i should
pass in a DataRow interface object into the data layer instead of
variables??
That way the data layer would check for the columns on the input'd
tablerow?? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Patchwork |
last post by:
Hi Everyone,
Please take a look at the following (simple and fun) program:
////////////////////////////////////////////////////////////////////////////
/////////////
// Monster Munch, example program
#include <list>
|
by: Proteus |
last post by:
Any help appreciated on a small perl project I need to write for
educator/teaching purposes. I have not programmed perl for some time, need
to get up to speed, maybe some kind souls hrere will help me on
this project? It looks to be a simple project, and I will start relearning
pearl, but any help appreciated!
I need to read and parse a simple text file (INPUT) containing multiple
choice quiz questions (with titles) and answers, and...
|
by: Raskolnikow |
last post by:
Hi!
I have a very simple problem with itoa() or the localtime(...).
Sorry, if it is too simple, I don't have a proper example.
Please have a look at the comments.
struct tm *systime;
time_t currentTime;
char day;
char month;
|
by: Peter |
last post by:
Hello
Thanks for reviewing my question. I would like to know how can I programmatically select a node
Thanks in Advanc
Peter
|
by: abcd |
last post by:
I am trying to set up client machine and investigatging which .net
components are missing to run aspx page.
I have a simple aspx page which just has "hello world" printed....
When I request that page like http://machinename/dir1/hellp.aspx
instead of running that page it starts downloding ...whats missing here
....why the aspx engine not running the page....
| |
by: dba_222 |
last post by:
Dear Experts,
Ok, I hate to ask such a seemingly dumb question, but I've
already spent far too much time on this. More that I
would care to admit.
In Sql server, how do I simply change a character into a number??????
In Oracle, it is:
|
by: Giancarlo Berenz |
last post by:
Hi:
Recently i write this code:
class Simple
{
private:
int value;
public:
int GiveMeARandom(void);
|
by: galiorenye |
last post by:
Hi,
Given this code:
A** ppA = new A*;
A *pA = NULL;
for(int i = 0; i < 10; ++i)
{
pA = ppA;
//do something with pA
|
by: Phillip Taylor |
last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm
having some trivial issues. In Visual Studio I create a web services
project and change the asmx.vb file to this:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
<System.Web.Services.WebService(Namespace:="http://
wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
|
by: Chris M. Thomasson |
last post by:
I use the following technique in all of my C++ projects; here is the example
code with error checking omitted for brevity:
_________________________________________________________________
/* Simple Thread Object
______________________________________________________________*/
#include <pthread.h>
extern "C" void* thread_entry(void*);
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |