[fpc-pascal] object model

spir ☣ denis.spir at gmail.com
Sat May 29 11:24:10 CEST 2010

On Sat, 29 May 2010 01:09:50 +0300
Alberto Narduzzi <albertonarduzzi at yahoo.com> wrote:

> Hi,
> > Struct is declared as "class" so it inherits from TObject if not other
> > class is especified.
> is that true? I don't mean not to trust you, but is the compiler 
> assuming that, or is it a FPC rule? IMO a class is a class, and doesn't 
> inherit from anything else. Unless specified. BTW, From who does TObject 
> inherit then?
> Just asking, I never declare anything as a pure class, or if I do I 
> don't care if it descends from TObject or not, actually...

Hum, there must be a root type, from which all others inherit primitive object mechanics. Such as, and mainly, accessing an attribute. Now, this needs not be obvious on the user-language side, but generally it is. So a test such as anything.isOfType(RootObject) always returns true.
Don't know about free pascal, but this is very probable (and I assumed it's true before the question was raised).

I take the opportunity to ask about inherited attribute (only methods in FP?) transmission and lookup: there are 2 common schemes:
* Copy: A subclass holds copies of (references to) inherited methods. So, lookup stops on an object's class.
* Delegation: A subclass delegates to its superclass when a looked up attribute is not found locally. (The superclass may itself delegate further, this up to the root class.)

Maybe this does not apply to, or is irrelevant in, a static language. I imagine the compiler can directly bind a reference to eg anObject.aMethod wherever aMethod may be defined; since it knows the whole hierarchy. So, this may have no impact at runtime.
I'd like to have more accurate information on this topic, because if it has any importance I will try to flatten as much as possible my object system; else I can "free-mindly" build vertical hierarchies, which often better mirror the semantics.

Thank you all,

vit esse estrany ☣


More information about the fpc-pascal mailing list