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

Class.New and DB mapping

Hello,

I map objects to a DB.

Currently, I have a shared function like :
clsCustomer.getForId(customerId as integer) as clsCustomer.
It returns Nothing when the customerId does not exist.

I would like to do that within the New :
clsCustomer.New(customerId as integer)

But how can I handle the non-existence of customerId then ?

Is it possible that New returns Nothing ?

Would it be better to throw an Exception ?

Thanks !
Nov 16 '06 #1
1 854

I wouldn't advise you to do anything hardcore like that within the
constructor. Logically, you should throw an exception, because constructing
the object with the required state has failed. You may also consider
setting an "IsValid" flag inside the class set to true or false depending on
constructor success or failure, however that is a slippery slope. My
preferred solution would be:
Dim theClass As New myClass

Result = theClass.LoadCustomer ( theID )

or in the case of your instance factory:

Dim theClass As myClass = clsCustomer.getForId ( customerId )

If theClass Is Nothing Then
' Failed.
End If
There is a lot to be said for being more explicit in code and less
obfuscating ;).

"myname" <no****@ihatespam.comwrote in message
news:45********@news.sncf.fr...
Hello,

I map objects to a DB.

Currently, I have a shared function like :
clsCustomer.getForId(customerId as integer) as clsCustomer.
It returns Nothing when the customerId does not exist.

I would like to do that within the New :
clsCustomer.New(customerId as integer)

But how can I handle the non-existence of customerId then ?

Is it possible that New returns Nothing ?

Would it be better to throw an Exception ?

Thanks !


Nov 16 '06 #2

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

Similar topics

20
by: Pierre Fortin | last post by:
Hi! "Python Essential Reference" - 2nd Ed, on P. 47 states that a string format can include "*" for a field width (no restrictions noted); yet... >>> "%*d" % (6,2) # works as expected ' ...
4
by: brianobush | last post by:
# # My problem is that I want to create a # class, but the variables aren't known # all at once. So, I use a dictionary to # store the values in temporarily. # Then when I have a complete set, I...
2
by: Krzysztof Stachlewski | last post by:
I tried to run the following piece of code: Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> o = object() >>> o.a...
1
by: steeren | last post by:
Hi, I'm new to this forum, so hello there. I have been working on getting some tool generated markup, to use a class name convention that can then be mapped to the platform its running on - with...
3
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename...
5
by: Muffin | last post by:
Does C# have a Set Collection class/functions of some sort? I can not seem to find it. A collection that I could extract thing like: Get only unique entries: {1,1,1,2,2,3,4,5,5,5,5,6,6} yields...
1
by: Jennifer Jazz | last post by:
My question is regarding the mapping of Class diagram to the C++ coding. There are 3 realtions in Class diagram 1) Assosication 2) Composition 3) Aggregation (Weak Composition). ...
3
by: shanmukhi | last post by:
hi all, i got a problem with struts. iam unable to find it. i have written an action class, form bean class and a jsp page on submitting form, request is going to action class but it is not...
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
5
by: Phil | last post by:
A file used by my application may be stored on a shared network drive, so that it can be accessed by different people using the same application. I have written some code that uses an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.