[fpc-pascal] class & object
tcoq at free.fr
Tue May 11 08:16:02 CEST 2010
See my comment below:
spir ☣ wrote:
> Second, theses texts seem to imply that classes only have drawbacks, compared to object types ;-) The reference does not compare the two models further, I guess; so why bother with a heavier system? Why did Delphi creators design such a complicated framework, while they already had the TP way?
> Is there a document somewhere describing the traits, advantages & drawbacks, and possibly the typical use cases, of both systems? Also, are there any data about compared performance using records+procs+funcs vs. object OO vs. class OO?
I coded in both TP and Delphi before moving to FPC. I did professional
programming with TP. We used Objects then. Most objects were created on
the heap, and used through pointers. There was a lot of indirections
(pointers) in the code, which was less readable and more prone to error.
Moving to Delphi was a delight because of that, since Classes are always
The second advantage of Classes is the mechanism that makes TComponent
work: the RTTI (Run-Time Type Inspection). This was not present in TP,
and is very useful to make generic components. Although Lazarus has not
fully gone through that path yet, and that packages are still statically
linked into the IDE (and our applications), it is already quite mature
in using this feature.
I understand Objects were kept in the original Delphi for compatibility
with TP code. For a while, it was possible to compile TP code with
Delphi (the 16 bit version). The one big advantage Objects have over
classes is their capability of being declared locally and used on the
stack, without referencing them. This could be useful in some tricky
situations, where one is not sure of which path will be executed in the
code, and one wishes to ensure the objects are deleted after use.
More information about the fpc-pascal