[fpc-pascal] Managed properties idea
michalis.kambi at gmail.com
Fri Oct 6 22:11:05 CEST 2017
2017-10-06 21:49 GMT+02:00 Michalis Kamburelis <michalis.kambi at gmail.com>:
> 2017-10-06 20:52 GMT+02:00 Marcos Douglas B. Santos <md at delfire.net>:
>>> In this case, in which you indeed want two of these features simultaneously,
>>> I advise COM interfaces myself :) That's why they are documented after all.
>> I can use it only to use reference counting.
> You can, but it's a little uncomfortable.
> If you use interfaces only for reference counting (not to share the
> API between some unrelated classes), then you define a single
> interface for each single class, repeating the same API -- methods,
> properties. It's possible, but it's just a lot of work. I have a lot
> of classes in my engine, and FPC RTL, FCL, Lazarus LCL define many
> more classes --- wrapping them all in an equivalent interface, only to
> get reference-counting for them, would imply a lot of work and
> constant maintenance.
> In contrast, something like C++ "shared pointer" is a feature that can
> be applied to any existing class, without the need to repeat it's API.
> See e.g. https://en.wikipedia.org/wiki/Smart_pointer . And once we
> have management operators (see Sven's pointers), we can implement
> something like this in Pascal. So you could use something like
> "TSharedPointer<TStringList>" and you get a reference-counted instance
> of TStringList.
P.S. It's possible to implement "shared pointers" using
reference-counted COM interfaces, too, without memory management
operators. You'd have something like "ISharedPointer<TStringList>",
and then it's comfortable too (no need to duplicate TStringList API).
So I'm not trying to say that management operators are the only way to
get something like "shared pointer".
The point of my text (on
) was that if you look for a feature that gives you ability to share
API between classes (and nothing else), then you want CORBA
interfaces. They are equivalent to "interface concept" from Java and
I feel that separation (one optional feature gives you
reference-counting, some other optional feature gives you ability to
share API between classes and requires to repeat this API) would be
More information about the fpc-pascal