On 16-Apr-07, at 11:38 AM, Dennis Birch wrote:

> On 4/16/07, Charles Yeomans <[EMAIL PROTECTED]> wrote:
>>
>> 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?
>
>> 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.
>
> Thanks Charles. I'm a little confused about this approach. Can you  
> elaborate?

You don't use the constructor directly.
You use a shared method that returns an instance of your class.
It becomes a factory (something that makes instances of the class)

Constructors in RB cannot return anything
They are (or should be) called Initializers. All memory is  
preallocated and the constructor is just setting values to some  
initial state.

>> The proper way to signal constructor failure is to raise an  
>> exception.
>
> That sounds like what I should be doing.

The factory pattern allows you to return nil although this may have  
other implications
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to