473,473 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Basic OOP questions for an expert

Hi everyone,

I have 2 classes, Company and Contact, a company can have 1 or more
contacts. A contact can only be in one company.

I have created a Company class object that contains all the properties
for my company. I have created a CompanyFactory class that has the
methods to Create, Retrieve, Update and Delete a company.

I have done the same for the Contact class and ContactFactory.

Questions.
1. If i want to get all the contacts for a company, should the method
go in the CompanyFactory or the ContactFactory? What parameter should
i pass in?

2. When called methods to retrieve company data, should you pass the ID
of the company into the function and return a company object, or should
you pass in a company object, with the companyID assigned, then return
a company object??

If anyone can point me in the direction of a good guide that describes
this, i would be grateful, or even better, if someone could write a
short example, that would be great.

This is my first time trying to write a OOP application, we are
converting or current system to be OOP based, and i would like to start
off on the right foot.

here is some code of company class and companyfactory, so someone can
say if i am doing it correctly. I have added a connectstring property
to my companyFactory as different users have different connection
strings, and thought this way would allow me to pass in the correct
connectionstring.

I havent included all sub and functions, as didnt think u would want to
see them all.

Class Company
Private _CompanyID As Integer
Public Property CompanyID() As Integer
Get
Return _CompanyID
End Get
Set(ByVal value As Integer)
_CompanyID = value
End Set
End Property

Private _CompanyName As String
Public Property CompanyName() As String
Get
Return _CompanyName
End Get
Set(ByVal value As String)
_CompanyName = value
End Set
End Property

Private _Reference As String
Public Property Reference() As String
Get
Return _Reference
End Get
Set(ByVal value As String)
_CompanyReference = value
End Set
End Property
End Class

Public Class CompanyFactory

Sub New()

_ConnectionString = String.Empty

End Sub

Sub New(ByVal pConnectionString As String)

_ConnectionString = pConnectionString

End Sub

Private _ConnectionString As String
Public Property ConnectionString() As String
Get
Return _ConnectionString
End Get
Set(ByVal value As String)
_ConnectionString = value
End Set
End Property

Public Function Add(ByVal pCompany As BuildSoft.Company) As
BuildSoft.Company

Dim SQL As New StringBuilder

' create SQL for inserting company into database
SQL.Append("INSERT INTO TBLCOMPANY (name, ref) values
(@name, @ref) Select @@SCOPE_IDENTITY")

Dim oConn As New SqlConnection(Me.ConnectionString)
Dim oComm As New SqlCommand(SQL.ToString, oConn)

Try

' add parameters to sql here
ocomm.parameters.add(new sqlparameter("@name",
pCompany.CompanyName))
ocomm.parameters.add(new sqlparameter("@ref",
pCompany.Reference))

' open connection
oConn.Open()

' begin the transaction for updating company data
oComm.Transaction = oConn.BeginTransaction

' execute command
pCompany.CompanyID = oComm.ExecuteScalar()

' commit transaction as no error has occurred
oComm.Transaction.Commit()

Catch ex As Exception

' roll back the transaction if an error has occurred
oComm.Transaction.Rollback()

Finally

' close connection
oConn.Close()

' dispose of command and connection
oComm.Dispose()
oConn.Dispose()

End Try

' return company added
Return pCompany

End Function

Aug 8 '06 #1
0 1044

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

Similar topics

8
by: slot | last post by:
Is there any problem to use "std::string" with unicode strings? When using std::string, does it have to be initialized? Is the following code OK? string s; S = "This is a test string"; ...
13
by: sieg1974 | last post by:
Hi, The function bellow returns the number of lines of a file. The length of the char variable __Line is 256, and I think it would allow me to store strings with up to 255 letters because the...
1
by: nuoo | last post by:
Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .NET Learn how to turn data into solutions with SQL Server 2000, Visual Basic .NET, and XML. Get a fundamental grasp of SQL...
23
Niheel
by: Niheel | last post by:
In a word Please Don't OK I admit that was 2 words but nothing in software was ever specified properly. Here are the reasons why you should post in the forum rather than PMing a Community...
6
by: BJMurphy | last post by:
Hi All, I am used to other SQL engines, and have a few basic questions-- 1)If I wanted to conditionally drop a table, does SQL Server have a way to natively do this? Many SQL implementations...
3
by: zhaowei003x | last post by:
for all : who are the best experts for c in the world?why ?what are they doing now?
102
by: dreamznatcher | last post by:
Hello, I'm considering a career switch to a more database-related job, but need help on a few questions and issues. I'm a Computer Engineering graduate and have always felt most comfortable...
40
by: aarklon | last post by:
Hi all, I was reading the book "C interview Questions" By J. Rajaram published in india by firewall media, after going through the book i have the following doubts 1) why the following...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
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...
0
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 ...
0
muto222
php
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.