473,657 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OOP / 3-Tier development questions

Developing a new app and am trying to make this my first truly
OOP/3-Tier app. I understand the principles of the presentation,
business, and data layers. I do, however, have some questions on where
certain functionality should be placed and how some things should be
implemented.

Let's use a simple example such as an application to manage customer
records (customer_id, first_name, last_name). I'd have a Customer
business object with ID, FirstName, and LastName properties. What I
don't understand is the following:

1. How do I obtain a Customer business object pre-loaded with data from
the database (customer_id 3 for example). I could create a constructor
in the Customer business class with the customer_id as a parameter and
have the constructor call the data layer to return a dataset containing
the customer's data and then set the properties accordingly. Is this
how this is normally accomplished? I could also have a method in the
Customer data layer that accepts a customer_id as a parameter and
returns a Customer business object. My only problem with this is that I
have it in my head that the presentation layer should never communicate
with the data layer. Some help here would be great.

2. How do I obtain a collection or ArrayList of Customer objects in the
case where I need to return more than one customer object? Such an
example would be a form that listed all customers. Calling a method in
the Customer data layer to return an ArrayList of Customer business
objects would work here as well, but this is breaking the same rule of
having the presentation layer working with the data layer. The other
option is to put a method in the Customer business object to return an
ArrayList of Customer business objects, but then my code has to
instantiate the Customer object simply to return more Customer objects.
This is unless I make the method in the Customer business object
shared.

3. Data layer methods to insert, update, delete database records -
Should the insert and update methods accept business objects as
parameters or should they accept a long parameter list that contains a
seperate parameter for each of the business object's properties?

Any help anyone can provide here is more than welcome. These issues
have been keeping me from developing an OOP/3-tier solution for quite
some time as I just can't seem to force myself to develop a system
without truly knowing how these issues should be tackled the proper
way.

Thanks in advance for your help!

Shawn Berg

Mar 6 '06 #1
5 1689
YTistic,

The term 3-tier is often used (the writers divide that in physical 3-Tier
applications and what is more popular a multi layer application).

What I read from you are you asking for multiple layers application (is that
true)?

Cor
Mar 6 '06 #2
I'm not sure of the difference to properly answer your question. I am
simply looking to isolate the presentation, business, and data logic
into seperate entities and my questions are about the proper
implementation of this.

Mar 6 '06 #3
Shawn,
I'm not sure of the difference to properly answer your question. I am
simply looking to isolate the presentation, business, and data logic
into seperate entities and my questions are about the proper
implementation of this.


The physical multi tier environment is in my opinion a very much mainframe
and because of that Unix approach.

All processes are done on the mainframe.

You are making Client/Server windowsapplicat ion a ClientSide application
that communicates with a ServerSide database. Physical separation on the
database side does not add much because the databaseserver (where I assume
SQLServer) is already strong enough.

On the clientsides in your Client/Server application is every user seperated
from another, so a physical multitier does add as well much.

However mixing up your Data and UI means that you will have multiple time
the same code in your OOP application while it mostly becomes spagethi..

In VB2002/2003 the designer did it like that. In VB2005 the datalayer is
seperated from the UI when you use the designer. Why don't you try that once
in VB2005.

Click Data->Add DataSource
Do what the Wizard ask
Click again Data a new tab is created use DataSource click that.
Drag it on your form.

Run.

Go to solution explorer (a tab in the right if it is not viewed, than use
that tab) and set in top of that show all files.

You will see now a nice xxx.vb file with the DataSet/DataAdapter class.
In that are all the classes needed for the UI to get the data.

You can create those classes of course yourself as well withouth the
designer.
I myself are keeping that dataset and the Dataretrieving part forever apart
(the last is to make with some statements very generic).

I hope this gives some ideas

Cor
Mar 6 '06 #4
typo
On the clientsides in your Client/Server application is every user
seperated from another, so a physical multitier does add as well much.

as well *not* much

Cor
Mar 6 '06 #5
iTISTIC wrote:
Developing a new app and am trying to make this my first truly
OOP/3-Tier app. I understand the principles of the presentation,
business, and data layers. I do, however, have some questions on where
certain functionality should be placed and how some things should be
implemented.

Let's use a simple example such as an application to manage customer
records (customer_id, first_name, last_name). I'd have a Customer
business object with ID, FirstName, and LastName properties. What I
don't understand is the following:

1. How do I obtain a Customer business object pre-loaded with data from
the database (customer_id 3 for example). I could create a constructor
in the Customer business class with the customer_id as a parameter and
have the constructor call the data layer to return a dataset containing
the customer's data and then set the properties accordingly. Is this
how this is normally accomplished? I could also have a method in the
Customer data layer that accepts a customer_id as a parameter and
returns a Customer business object. My only problem with this is that I
have it in my head that the presentation layer should never communicate
with the data layer. Some help here would be great.
I'm going to assume that you're talking about software tiers (as
opposed to physical tiers). The way it's usually handled at the firms
I've worked for is as follows:

1. Business object just like you described.
2. Controller object that takes business objects as arguments, and
passes their properties to data objects.
3. Data objects that encapsulate stored procedures for inserting,
updating, deleting, and selecting objects.

Thus, you mught have the following (abbreviated):

' Business Object
Public Class Employee

Private m_id As Integer
Public Property ID As Integer
Get
Return m_id
End Get
Set(ByVal Value As Integer)
m_ID = Value
End Set
End Property

Private m_firstName As String
Public Property FirstName As String
Get
Return m_firstName
End Get
Set(ByVal Value As String)
m_firstName = value
End Set
End Property

End Class

Public Class EmployeeControl ler

Public Shared Function Load(ByVal ID As Integer) As Employee

Return MyDataObject.Lo ad(ID)

End Function

End Class
Friend Class EmployeeDac

Public Shared Function Load(ByVal ID As Integer) As Employee

Dim cn As New SqlConnection( "server=foo;dat abase=bar;")
Dim cmd As New SqlCommand(cn)
Dim dr As System.Data.Sql Client.SqlDataR eader

cmd.CommandType = CommandType.Tex t
cmd.CommandText = "SELECT * FROM foo WHERE ID = " & ID

Try
dr = cmd.ExecuteRead er()
If dr.Read() Then
bo = New MyBusinessObjec t()
bo.FirstName = CStr(dr("FirstN ame")) ...
End If
Catch ex As Exception
Throw
Finally
If dr IsNot Nothing THen
dr.Close
End If
cmd.Close
cmd.Dispose
End Try

Return bo

End Function

End Class
2. How do I obtain a collection or ArrayList of Customer objects in the
case where I need to return more than one customer object? Such an
example would be a form that listed all customers. Calling a method in
the Customer data layer to return an ArrayList of Customer business
objects would work here as well, but this is breaking the same rule of
having the presentation layer working with the data layer. The other
option is to put a method in the Customer business object to return an
ArrayList of Customer business objects, but then my code has to
instantiate the Customer object simply to return more Customer objects.
This is unless I make the method in the Customer business object
shared.
Lots of folks use the built-in stuff for returning datasets and
sprinkling them throughout their code. Personally, I detest the idea of
referencing ANY object from the System.Data namespaces outside of the
data layer. I have a program that writes type-safe objects for each
table in the database, and collections of them. Then I return the
collections. A LoadAll() method on the controller and data object
return the multiple rows. (Because I also use inheritance, the derived
class supports customized selection criteria so I can get just about
whatever I want.)

Nowadays, however, I skip the collection classes and use generics. For
instance, I use List(Of Employee) instead of a custom
EmployeeCollect ion derived from System.Collecti ons.CollectionB ase, and
on the DAC:

Friend Shared Function LoadAll() As List(Of MyBusinessObjec t)

It's terribly handy.
3. Data layer methods to insert, update, delete database records -
Should the insert and update methods accept business objects as
parameters or should they accept a long parameter list that contains a
seperate parameter for each of the business object's properties?
SHORT ANSWER: Pass objects. As long as the DAC classes and the
Controller classes are in the DLL, the compiler can handle it (thanks
to the miracle that is metadata). You won't have to do much typing, and
if you decide later on that you want to add fields to the objects, you
won't have to modify the controller and the DAC -- you'll just have to
adjust the DAC.

LONG ANSWER: I was troubled by this question for a while too. For some
reason, I had it in my head that the parameter lists for my methods
should all look the same. Thankfully, someone beat that nonsense out of
me.

The best answer is, probably, that the ideal parameter list depends on
the operation being performed. For some operations, you won't have an
object, or you'll only need a tiny piece of its data. For others,
you'll need the whole object. For instance, if you're deleting objects,
or checking whether or not they exist, all you need is the primary key.
If you're saving the object (either inserting or updating), you'll need
the whole thing.

The signatures I use tend to look like this:

Public Shared Sub Delete([primary key])
Public Shared Sub DeleteAll()
Public Shared Function Exists([primary key])
Protected Shared Sub Insert(MyBusine ssObject)
Public Shared Sub Load([primary key]) As MyBusinessObjec t
Public Shared Sub LoadAll() As List(Of MyBusinessObjec t)
Public Shared Sub Save(MyBusiness Object)
Protected Shared Sub Update(MyBusine ssObject)

I also have overloaded versions of Delete, DeleteAll, Insert, Save, and
Update that include a SqlTransaction as the last parameter, but those
occur ONLY on the DAC. That way, the controller can combine multiple
updates under the same transaction. For instance, if saving object A
also requires an update to object B, then the controller can
instantiate a transaction, update A, insert into B, and then commit the
transaction. This keeps knowledge of transactions *out* of the business
layer. For instance:

Public Class EmployeeControl ler

Public Sub Save(ByVal item As Employee)
Dim cn As New SqlConnection(" Server=foo;Data base=bar;")
Dim tx As SqlTransaction = cn.BeginTransac tion

Try
EmployeeDac.Sav e(item, tx)
AuditTrailDac.S ave(item,tx)
tx.Commit()
Catch(ex As Exception)
tx.RollBack()
Throw
Finally
cn.Close()
cn.Dispose()
End Try

End Sub

End Class

Personally, I find that it's burdensome to pass potentially LOTS of
parameters around from one procedure to the next (simply from all the
typing!), so I *tend* to pass the objects around until it's absolutely
necessary to break them down. There are always exceptions, though, so
use your best judgement. Don't sweat getting it 100% right the first
time. If you do that, you'll never finish the product; you're bound to
make mistakes, and you'll learn from 'em.
Any help anyone can provide here is more than welcome. These issues
have been keeping me from developing an OOP/3-tier solution for quite
some time as I just can't seem to force myself to develop a system
without truly knowing how these issues should be tackled the proper
way.

Thanks in advance for your help!

Shawn Berg


Good luck! And I hope this helps! Drop me a line if you need any more
help.

Mar 6 '06 #6

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

Similar topics

0
1224
by: iTISTIC | last post by:
I've read the following articles a few times over: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/tdlg_rm.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vetchWebProjectsSourceControlIntegrationInVisualStudioNET.asp I have chosen to run in "Isolated" mode, and have VSS setup on a project server, and have already successfully created a local web
1
1451
by: Eddie Borden | last post by:
Does anyone have a runtime version of Access2003? If so I would greatly appreciate a copy of it! How do you turn off the Language Bar for all users on a multi user system running Citrix? This is in the upper right hand part of the screen. How do you turn off the "Type a question for help field"? This is in the upper right hand part of the screen.
9
1168
by: Chris | last post by:
I would love to be pointed in the direction of resources that help better understand the following (I've spent considerable time searching the MS website): 1.) As a ASP.NET developer I've traditionally worked in the environment of a workstation with VS.NET and a Windows2003 server with IIS6.0 and SQL Server. Is that the most popular model. I know that if a developer needed to travel that they could install IIS and Sql Server locally, but...
16
1895
by: Linus | last post by:
Being a ASP developer for a consultant company thinking of starting developing with ASP.NET I have read literally hundreds of web pages and posts in discussion forums on the Internet to get an idea of what we will need to adapt to. I have read Microsoft’s “Team Development with Visual Studio .NET and Visual SourceSafe” and tried to set up a development environment as recommended using the “Isolated model”. However, many questions...
8
1623
by: Old VB6 Guy | last post by:
First of all, sorry if crossposting bothers you -- I don't normally do it, but both of these groups seem relavant to my questions. Alright, the time has finally come to make an investment in time and money to jump start my career again. I am currently a VB6/ASP programmer, but worse yet, I am in a company that has me doing (yuch!) support work mostly and I get extremely limited programming "bones" thrown to me these days. In short, I...
8
2758
by: situ | last post by:
Hello all, i have Database1 and database2, is it possible to make database connection to database2 by running stored procedure on database1. Thanks and Regards Situ
3
4403
by: robtyketto | last post by:
Im a student and in preparation for a testIve been given the test questions (or thereabouts, they may be asked in different words or from another perspective). I've been told that they do not require long answer, short punchy bullet points are fine, and I guess to justify your points too. So since I got up this morning in the UK for the last 3hrs Ive done some resarch and come up with a set of notes/answers. Remembering this is an...
1
999
by: =?UTF-8?Q?=C5=81ukasz_D=C4=85bek?= | last post by:
Hello! I'm newcomer to Python development and I have some questions (I didn't found answers for these): 1. Some bugs at bugs.python.org are assigned but it didn't changed for many months (example: http://bugs.python.org/issue1692335). Is that bugs closed (maybe somebody forgot to close it on website?), work in progress or other? 2. Is Python 2.5 still developed? 3. Is this good mailing list for such questions?
0
695
by: =?UTF-8?Q?=C5=81ukasz_D=C4=85bek?= | last post by:
Thanks for reply. From: "Victor Noagbodji" <noagbodjivictor@gmail.com>: I have been coding in Python for about 1 year :) (I even have a book about Python 2.4). For "Python development" I meant developing Python itself. I also have some C skills, so I wanna help to develop Python. Currently I'm diving into CPython code but it is very complicated for me. When I get some overview I'm going to send some patches form Py3k. If my skills are...
0
8737
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...
1
8509
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,...
0
8610
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
7345
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 projectplanning, coding, testing, and deploymentwithout 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
6174
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
5636
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
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
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
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.