|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Class.New and DB mappingHello,
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 ! 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 ;). Show quoteHide quote "myname" <nospam@ihatespam.com> wrote in message news:455c21be$1@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 ! > >
How to get app.config info from code in a referenced class
VB.NET and MDAC+JET update access mdb Strange but true ... im at a loss help !!! question about inheritance and Imports statement XML over TCP directing output to selected monitor in a multi-monitor desktop calling a .bat program in a vb .net program It's impossible to debug code in MyApplication_UnhandledException how to compile VB dll file in VS 205 in .net framework1.1 (not 2.0 |
|||||||||||||||||||||||