Discussion:
[fpc-other] Object Pascal Interface Delegation, but in Java
Graeme Geldenhuys
2017-09-08 14:59:03 UTC
Permalink
Hi,

Does anybody familiar with Object Pascal and Java know if Java supports
something similar to Object Pascal's Interface Delegation "implements
syntax" functionality?

Regards,
Graeme

_______________________________________________
fpc-other maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/lis
Marco van de Voort
2017-09-09 16:39:52 UTC
Permalink
Post by Graeme Geldenhuys
Does anybody familiar with Object Pascal and Java know if Java supports
something similar to Object Pascal's Interface Delegation "implements
syntax" functionality?
That is often called delegation, and if you search for java and delegation,
it seems not (which is not THAT surprising IMHO):

https://stackoverflow.com/questions/2989005/delegation-example-regarding-java-context
_______________________________________________
fpc-other maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/c
Graeme Geldenhuys
2017-09-09 17:17:12 UTC
Permalink
Post by Marco van de Voort
That is often called delegation, and if you search for java and delegation,
Thanks Marco. So it is actually similar to Object Pascal where you use
object composition, but with Object Pascal's "implements" keyboard the
interface is automatic in the new class's interface. Where-as with Java
you have to define the interface and then delegate the calls to the
composition object. I'm sure Eclipse must have that code-generation
functionality built-in or an add-on that can do that.

So Object Pascal is just a bit more convenient, but the end-result
(functionality) is the same in.

Thanks again for your input.

Regards,
Graeme
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key: http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-other maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/m
Graeme Geldenhuys
2017-09-09 21:55:02 UTC
Permalink
Post by Graeme Geldenhuys
I'm sure Eclipse must have that code-generation
functionality built-in or an add-on that can do that.
And my guess was correct. :) In Eclipse select "Source -> Generate
Delegate Methods". Select the field variable that will do the
delegation. Eclipse fully implements all (or selected) methods of
delegate member as delegate methods.

Regards,
Graeme

_______________________________________________
fpc-other maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-ot
Marco van de Voort
2017-09-09 23:31:11 UTC
Permalink
Post by Graeme Geldenhuys
Post by Marco van de Voort
That is often called delegation, and if you search for java and delegation,
Thanks Marco. So it is actually similar to Object Pascal where you use
object composition, but with Object Pascal's "implements" keyboard the
interface is automatic in the new class's interface. Where-as with Java
you have to define the interface and then delegate the calls to the
composition object. I'm sure Eclipse must have that code-generation
functionality built-in or an add-on that can do that.
So Object Pascal is just a bit more convenient, but the end-result
(functionality) is the same in.
Well, with Pascal's syntax you could link through VMT fragments, without
actually bouncing through additional code.

And you don't risk forgetting adding a method to existing classes if you add
one to the interface, always a risk with manual workarounds like the
codegeneration tools that assume everything is designed at once top-down and
only then implemented.

_______________________________________________
fpc-other maillist - fpc-***@lists.freepascal.org
http://lists.f
Graeme Geldenhuys
2017-09-10 08:01:07 UTC
Permalink
Post by Marco van de Voort
And you don't risk forgetting adding a method to existing classes
Java will give a compilation error if you do, so nothing to worry about
there.
Post by Marco van de Voort
always a risk with manual workarounds like the
codegeneration tools that assume everything is designed at once top-down and
only then implemented.
Eclipse allows you to run the "wizard" multiple times and will add and
remove code depending on what you ticked and unticked. Eclipse's code
generation is very impressive.


Regards,
Graeme
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key: http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-other maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-
Loading...