473,388 Members | 1,198 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,388 software developers and data experts.

Best Practices Question

As a general rule, is it better to place database calls as part of the
object the operate on or just put all the calls in thier own namespace?

Ex
Dim userObject = New UserClass()

userObject.InsertUser()

Or

Dim DBCalls = New SystemDBCalls()
DBCalls.InsertUser(userObject)

I realize there are a few different ways you can code this but you get the
idea. Or perhaps this is just a matter of preference or function?

Thanks,
Jim
May 21 '06 #1
5 902
http://groups.google.com/group/micro...af85a2e6593dfa
I hit send before pasting the link
"JimO" <jo************@DEF-earthlink.net> wrote in message
news:0T*****************@newsread4.news.pas.earthl ink.net...
As a general rule, is it better to place database calls as part of the
object the operate on or just put all the calls in thier own namespace?

Ex
Dim userObject = New UserClass()

userObject.InsertUser()

Or

Dim DBCalls = New SystemDBCalls()
DBCalls.InsertUser(userObject)

I realize there are a few different ways you can code this but you get the
idea. Or perhaps this is just a matter of preference or function?

Thanks,
Jim

May 21 '06 #2

The object itself shouldn't have db calls in it.

It should be an object, with properties , methods, and sometimes events.

In the datalayer, you will populate either a IDataReader or a DataSet, which
you will use to create your objects.

Then, I usually have another class, in the biz layer.

The biz layer will call the datalayer, it will get the IDataReader or
DataSet.

This class will then loop over the IDataReader or DataSet, to create your
objects.
Your objects should not be tied to a specific database, which is what you
will end up having going with the "integrated db route".

See my other post:

"JimO" <jo************@DEF-earthlink.net> wrote in message
news:0T*****************@newsread4.news.pas.earthl ink.net...
As a general rule, is it better to place database calls as part of the
object the operate on or just put all the calls in thier own namespace?

Ex
Dim userObject = New UserClass()

userObject.InsertUser()

Or

Dim DBCalls = New SystemDBCalls()
DBCalls.InsertUser(userObject)

I realize there are a few different ways you can code this but you get the
idea. Or perhaps this is just a matter of preference or function?

Thanks,
Jim

May 21 '06 #3
Thanks for the help.

Jim
"sloan" <sl***@ipass.net> wrote in message
news:ef**************@TK2MSFTNGP05.phx.gbl...
http://groups.google.com/group/micro...af85a2e6593dfa

I hit send before pasting the link
"JimO" <jo************@DEF-earthlink.net> wrote in message
news:0T*****************@newsread4.news.pas.earthl ink.net...
As a general rule, is it better to place database calls as part of the
object the operate on or just put all the calls in thier own namespace?

Ex
Dim userObject = New UserClass()

userObject.InsertUser()

Or

Dim DBCalls = New SystemDBCalls()
DBCalls.InsertUser(userObject)

I realize there are a few different ways you can code this but you get the idea. Or perhaps this is just a matter of preference or function?

Thanks,
Jim


May 21 '06 #4
A separation of business objects from data access layer is highly desired.
Your "layers" would look something like:

UI --> Business Objects --> Data Access --> DB (Stored procs, etc.)

This way, you can focus on pure busiess in BO, without having to worry about
how you will persist this data in the database.

--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"JimO" <jo************@DEF-earthlink.net> wrote in message
news:0T*****************@newsread4.news.pas.earthl ink.net...
As a general rule, is it better to place database calls as part of the
object the operate on or just put all the calls in thier own namespace?

Ex
Dim userObject = New UserClass()

userObject.InsertUser()

Or

Dim DBCalls = New SystemDBCalls()
DBCalls.InsertUser(userObject)

I realize there are a few different ways you can code this but you get the
idea. Or perhaps this is just a matter of preference or function?

Thanks,
Jim

May 22 '06 #5
I just want to point out that there are rare occasions when custom business
objects are 'too complex' to have the CRUD in a DAL. In this case, we use the
traditional and still 'correct' pattern of putting CRUD behavior inside our
complex business objects. These can be XMLSerialized sent to a server,
deserialized and their CRUD used on the server. It is a rarely needed, but
viable and correct option.
The standard way is to use tiers and seperate concerns between the BLL and
DAL.

"Manohar Kamath" wrote:
A separation of business objects from data access layer is highly desired.
Your "layers" would look something like:

UI --Business Objects --Data Access --DB (Stored procs, etc.)

This way, you can focus on pure busiess in BO, without having to worry about
how you will persist this data in the database.

--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"JimO" <jo************@DEF-earthlink.netwrote in message
news:0T*****************@newsread4.news.pas.earthl ink.net...
As a general rule, is it better to place database calls as part of the
object the operate on or just put all the calls in thier own namespace?

Ex
Dim userObject = New UserClass()

userObject.InsertUser()

Or

Dim DBCalls = New SystemDBCalls()
DBCalls.InsertUser(userObject)

I realize there are a few different ways you can code this but you get the
idea. Or perhaps this is just a matter of preference or function?

Thanks,
Jim


Aug 7 '06 #6

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

Similar topics

136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
13
by: john doe | last post by:
A quick question, about so-called 'best practices', I'm interested in which of A/B of the two examples people would choose, and why. public enum MyEnum { Option1 = 0, Option2 = 1, Option3 =...
1
by: Vincent V | last post by:
Hey i am just starting a new project and from the start i want to make sure my app is as Object Orientated as possible I have a couple of questions in relation to this Question 1: Should i...
3
by: Derek Martin | last post by:
Hi list, I have been doing VB.Net for quite a while now and just now getting into the forray of ASP.Net using VS2003. I have created our development website and now we are ready to start putting...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
8
by: SStory | last post by:
When I right a class, I am wondering what are the best practices for error handling? Do I try..catch and trap the error and if so what do I do with it? Because most likely the class user will...
15
by: Andrew Brampton | last post by:
Hi, This may sound a odd question, but I wanted to know how you return a list of data from a function. These are some of the ways I know how, and I was wondering which method you normally use....
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
17
by: 2005 | last post by:
Hi In C++, are the following considered best practices or not? - passing aguments to functions (ie functions do not take any arguments ) - returning values using return statement Anything...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.