At 17:02 13/06/01 , you wrote:
>  function GetIterator: IIterator
>
>Auto gargage collection doesn't seem to me to summarize the significance
of this. You've

I don't think you can overstate the significance of garbage collection or
more generally, resource management. Its straightforward to clean up after
yourself where the lifetime and usage of a resource is limited to the scope
of a function or an object. But consider a public function:

function GetIterator: TIterator

Who is responsible for destroying the returned object, the producer or the
consumer? Its not obvious. The answer is only found through asking, or
associated documentation, or reading the source (where available). And that
assumes that all users will go to the trouble of finding out, which is
drawing a longish bow.

Assume further that we've established who is responsible for lifetime and
everybody plays by the rules. Great. Now, it turns out that the producer
and the consumer are in different threads, and resources are released upon
thread termination. What happens when the threads die in the wrong order?
AV-a-gogo. So now we also need to enforce thread finishing order.

By changing to: 

function GetIterator: IIterator

which returns an interface, all these issues disappear, 9 times out of 10.
The iterator gets cleaned up when the last reference is released - end of
story. The remaining 1 time I attribute to poor design, which will _always_
prevail over the best defences!

Paul.
----------------------------------------------------------
 Paul Spain,  Excellent Programming Company
 mailto:[EMAIL PROTECTED]
----------------------------------------------------------

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to