On Apr 16, 2007, at 12:26 PM, Dennis Birch wrote:
> Is it possible to not return an instance of a class from its
> constructor?
>
> For example, say my constructor for SomeClass is:
>
> Sub Constructor(rs As RecordSet)
> dim d As Date
> dim fld As DatabaseField
>
> fld = rs.Field("EntryDate")
> if fld = nil Then Return
>
> // assign values to class properties
>
> End Sub
>
> Instead of returning a useless instance of SomeClass with none of its
> properties filled to the method that called the constructor, it would
> be nice if it were possible to return a nil object. Is it possible to
> do that?
Not exactly. If you want to return nil if the constructor fails,
then you can define a shared method NewSomeClass(rs as RecordSet) as
SomeClass and call it. The proper way to signal constructor failure
is to raise an exception.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>