[fpc-devel] weak referencing (was Suggestion:.....)

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Sep 22 17:11:08 CEST 2014


On 22 Sep 2014, at 16:44, Peter Popov wrote:

> Another comment: If referenced objects all derive from a single  
> base, then, the user cannot possibly have another hierarchy, which  
> uses ref. objects. As I mentioned earlier, I do this explicitly for  
> an object well down my hierarchy. So, it seems to me you still need  
> something like:
>
> -- code --
>
>
> TRefObject = referenced class(TWhateverBase)
> end;

I would strongly recommend against that. Referenced and unreferenced  
objects are completely different beasts with different behaviours. If  
you allow that, you get all kinds of problems down the line. E.g. you  
either have to forbid assigning a TRefObject to a TWhateverBase (which  
runs counter to a very basic OOP principle), or allow it and then have  
the programmer deal with the resulting reference counting mess-ups.

Just like Objective-C and C++ classes cannot derive from each other,  
and just like Delphi-style classes and TP-style objects and objcclass  
and cppclass cannot derive from each other, so should reference  
counted and non-reference counted classes not be able to derive from  
each other. If you want to mix reference counted and non-reference  
counting functionality, use the existing interface-based pattern  
instead, or possibly some kind of delegation pattern.


Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140922/33e81a3f/attachment.html>


More information about the fpc-devel mailing list