"David McCallum" <
XXXX@XXXXX.COM>a écrit dans le message
de news:
XXXX@XXXXX.COM...
| All my experience of interfaces are with Java, which I fully understand,
and
| I think I have got the basics of with Delphi, but a couple of things still
| worry me. I am sure there are a lot more but here we go:
You have to understand that Delphi interface, prior to .NET, use the COM
pattern, even if the interfaces are not for COM support.
| 1. In Java if Implementation2 extends Implementation1, and a class
| implements Implementation2, then the class must have all the methods
defined
| in both implemntations. But In Delphi, I understand that I have to use
some
| thing like:
|
| MyClass=Class(Implementation2, Implementation1)...
|
| Do I really need to mention both implmentations?
Yes, this is a requirement of the COM spec :-( However, if you implement the
base interface in one class and then implement the derived interface in a
derived class, then you only need to mention the derived interface in the
declaration of the derived class.
| 2. What is the GUID I see all over the place for?
Because Delphi uses the COM model, it relies on the GUID for its uniqueness
of identity. If you don't include a GUID in an interface declaration then
you can not cast or use "as" to cast to another interface. You also can not cast
an interface back to the underlying object. Once again :-(
| 3. What is reference counting?
Reference counting is meant to allow the "server" COM object to free itself
when the last interface reference to it falls out of scope. Don't forget
that Delphi doesn't support garbage collection. Most of us who use
interfaces in Delphi use reference counting as a poor-man's garbage
collection as a side effect.
OTOH, interfaces in Delphi for .NET do not require GUIDs or implement
reference counting. They are designed primarily as a language feature, not
primarily as a COM feature that also gives you a language feature. Much more
like the Java way of doing things.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer