[fpc-devel] Class extension

Jonas Maebe jonas.maebe at elis.ugent.be
Thu May 20 14:47:18 CEST 2010


On 20 May 2010, at 14:29, Matt Emson wrote:

> In Objective-C, the Category often seems a lot like the Partial  
> class in a superficial way. It is the same kind of idea - a breaking  
> up of a class in to sections. Sections can be added and removed in a  
> similar way. However the category goes further (as Objective-C  
> always seems to) and allows functionality to be plumbed in to an  
> existing class, without the need to alter the original source code -  
> indeed you actually do not need the source at all. This is what I  
> envisioned when I stated the above "class extension". It could also  
> be seen as a mechanism to overcome the issues often encountered with  
> an OO system lacking multiple inheritance. One of the more  
> interesting features of Categories in Objective-C is the ability to  
> replace methods in the base class, but using the same signature.

Having implemented support for Objective-C/Pascal categories in the  
compiler, I don't think that this concept can be translated to the  
(Delphi-compatible) Object Pascal model/implementation. It only works  
in Objective-C/Pascal because there all dispatching is based on the  
name of the method/selector (instead of based on VMT offsets or static  
binding).

It may be doable with a separate class hierarchy (like  
TInterfacedObject for COM) and compiler/RTL magic (that would probably  
duplicate large parts of the Objective-C run time's functionality to  
get everything running at a reasonable speed), but in that case it  
might be more worthwhile to add support for GNUStep and extend the  
Objective-Pascal support to all platforms (since it wouldn't work with  
the regular Object Pascal classes in the RTL anyway). Objective-Pascal  
and Object Pascal can be mixed in the same file, so you can use  
delegation and other ways to bridge the two kinds of classes.


Jonas



More information about the fpc-devel mailing list