[fpc-pascal] Question about interfaces
Michael Van Canneyt
michael.vancanneyt at wisa.be
Wed Mar 23 09:45:06 CET 2005
On Tue, 22 Mar 2005, ml wrote:
>>> Quoting Marco van de Voort <marcov at stack.nl>:
> Like first, I wouldn't like to spam this mailing list about interfaces.
> Can I contact you directly or somewhere else?
> I would like to try to patch some things but I would probably have few
> questions how to implement it to satisfy everybody, or the general
> interfaces idea and implementation.
> One major problem with interfaces is class <=> interface <=> class
> inflexibility and this is the root of everything.
Classes are fundamentally different from Interfaces. Interfaces only
specify a set of methods (a VMT, essentially) where classes also
contain data. When a class implements an interface, it just means that
all methods as specified in the interface are available.
> imagine interfaces declared IA, IB, IC, ID, and all standalone
> a: IA; b: IB; c: IC; d: ID; obj: TA;
> a := obj; // result is pointer(obj) + 12;
> b := obj; // result is pointer(obj) + 16;
> c := obj; // result is pointer(obj) + 20;
> // Following is nonsense, its just like "as" would be direct
> // call to exception if you try to use class that inherits more
> // than one interface
> a := (object as IA); // correct
> b := (object as IB); // returns pointer to the first interface vmt=IA
> c := (object as IC); // returns pointer to the first interface vmt=IA
> // there's no way to do again it's like direct call to exception
> obj := a; // returns pointer(obj) + 12 ???
This is nonsense. You cannot assign an interface to a class.
A class IMPLEMENTS an interface, it is not an interface.
More information about the fpc-pascal