Passing Class Structures.

G

Greg

I'm not sure I am using the proper language here, but, I'm pretty sure I
should be able to get across what I want to ask.

I have a three teir project I am working on. It contains a UI, DataAccess
and BusinessLogic teirs.

In the BusinessLogic component, I have an Employee Class that contains
Employee information named EmployeeClass.

So, in my UI component in a form I populate this class component with my
employee information. For example, I do the following to populate the class
object.

dim objEmployee as EmployeeClass
objEmployee = new EmployeeClass
objEmployee.FirstName = me.txtFirstName.text
objEmployee.LastName = me.txtLastName.text

So, with the objEmployee class object I want to pass it to my function I
have in my BusinessLogic component called InsertEmployee. I may do some
additional data cleanup here before inserting the employee. Now, once the
BusinessLogic component is done with the class object, I want to pass it on
to the DataAccess module InsertEmployee function. The InsertEmployee function
exists in both my BusinessLogic and DataAccess modules.

Now, my UI has a reference to the BusinessLogic components and my
BusinessLogic component has a reference to the DataAccess component.

My question is, how can I pass my objEmployee object from the BusinessLogic
component to the DataAccess component when the DataAccess component does not
know anything about the objEmployee class object?

My thought is to pass the entire employee objEmployee object at once. Thus
the DataAccess InsertEmployee function would look like this.

Function InsertEmployee(byval objEmployee as objEmployeeClass) as boolean
Do stuff in here with the objEmployee object and insert into database.
End Function

My problem is that the DataAccess component is not referenced to the
BusinessLogic component. I'm not sure it would be a good idea to setup a
reference to the BusinessLogic component because it kind of defeats the
purpose I think .

I hope I was able to convey what it is I am trying to do. If anyone has any
ideas or suggestions I'd appreciate to hear them.
 
G

Guest

My question is, how can I pass my objEmployee object from the
BusinessLogic component to the DataAccess component when the
DataAccess component does not know anything about the objEmployee
class object?

Create a library (DLL) which contain the definitions of your data objects.
Your two projects (business layer and data layer) will reference this third
project. This allows your two layers (or entire application for that
matter) to share a common set of data objects.
 
C

Cor Ligthert[MVP]

Greg,

It is a nice theory, however as soon as your solution becomes more complex,
then you will see that the UI has to pass information about the data to the
business layer and the business layer to the data layer.

You are not only showing a class in an UI in textboxes or in one grid and
you are not only getting the data for a class however, real information that
all has their own rules for showing.

Mostly you want to update that data as well.

Therefore I keep it with an UI, which is very clean. A Business Interface
and in principle a very small DataLayer which has all standard features for
DataAccess.

The benefit from this is, that customers want often changes in the UI or
want more of them with in fact the same data, while the business interface
is often something they don't see and therefore is more static (and usable
for more UI's)

Cor
 
R

RobinS

You should put the update method(s) in your business logic class, and have
the update method call the data access layer to do the update.

For example, I would have a Save method that calls a method called
"ExecuteDataTable" in my data access layer, passing in the list of
parameters, and the ExecuteDataTable would do the actual update against the
database. Note that the DAL is ignorant of what it is updating. The business
object class also passes in the name of the sp to run.

There's a keen book that explains how to do this really, really clearly,
including keeping track of the state of the business object (deleted,
updated, etc). The book is called Doing Objects in VB2005, by Deborah
Kurata. You can also try Googling her and find her website; she probably has
the code posted, and looking through it might be illuminating. Post back if
you can't find it, and I'll track it down.

RobinS.
GoldMail, Inc.
----------------------------------------------
 
F

Family Tree Mike

No, you are just defining a utility library that is common between two (or
more) layers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top