Eidolon,
Rather then returning Nothing and then needing a lot of checks for Nothing.
I would throw an exception as the others suggest or I would consider the
CreateCustomer Factory Method and the NullObject Pattern.
A NullObject is a specific case of the Special Case pattern:
http://www.martinfowler.com/eaaCatalog/specialCase.html
Basically the Customer.CreateCustomer routine that Marina suggests would
return either new Customer or a new NullCustomer.
The NullCustomer inherits from Customer, however all the methods return
reasonable defaults & all the setters are "ignored". This allows you to code
all your routines so they can operate on a Customer object, without
requiring a lot of:
Dim theCustomer As Customer = Cutomer.CreateCustomer(x)
If theCustomer Is Null then
' don't have a customer do one thing
Else
theCustomer.DoSomethingInteresting()
End If
You can use:
Dim theCustomer As Customer = Cutomer.CreateCustomer(x)
theCustomer.DoSomethingInteresting()
The DoSomethingInteresting routine on NullCustomer would not perform any
real work.
Hope this helps
Jay
P.S. Do not respond to any email your Reply to may have caused, if you want
a response, please post in the newsgroup, this way others can see the
answers & hopefully benefit from your questions. thanks for understanding.
"Eidolon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there any way that you can write your constructor so that it returns
> nothing?
>
> For example:
> Take a Customer object which has a constructor whose constructor has the
> signiture:
>
> Public Sub New(CustomerID as String)
>
> What i would like to do is to write it so that the the actual code of the
> constructor goes something like the following pseudo-code:
>
> <pcode>
> Dim dt as datatable = getDataTable(SELECT * FROM CUSTOMER WHERE CUSTID
=
> CustomerID)
> If dt.Rows.Count = 0 then
> return nothing
> Else
> InitializeMe(dt.Rows(0))
> End if
> </pcode>
>
> This way from my client code i can do something like:
>
> <code>
> Dim tmpCust As Customer = New Customer(MyParameter)
> If IsNothing(tmpCust) Then
> ShowNoCustMsg
> Else
> ConitnueOn()
> End If
> </code>
>
> Thanks in advance.
>
>