Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-03

double dispatch

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jorge Aldo G. de F. Junior

Can FPC deal with double-dispatch ?

Say you have an object defined as :

Type
TMyObject = Class
Public
Procedure DoSomething(Const aObject : TObject); Virtual;
End;
TMyParameterObject = Class
Public
End;
TMyOtherParameterObject = Class
Public
End;

Can you do something like :

Type
TMyOtherObject = Class(TMyObject)
Public
Procedure DoSomething(Const aObject : TMyParamaterObject); Override; Overload;
Procedure DoSomething(Const aObject : TMyOtherParameterObject);
Override; Overload;
End;

And have the run-time choose the correct implementation to call by looking at the object type ?

leledumbo
to Jonas Maebe
No, because overloading works the same as in C++ (determined statically at

compile time).

Are you sure, Jonas? Because I've been able to implement visitor pattern which is a kind of double dispatch. Of course it's not implemented like the example posted by the OP, but more like a simulation explained in http://en.wikipedia.org/wiki/Double_dispatch wikipedia .

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/double-dispatch-tp3987828p4072095.html Sent from the Free Pascal - General mailing list .
Jonas Maebe
to leledumbo
leledumbo wrote
> No, because overloading works the same as in C++ (determined statically at > compile time). Are you sure, Jonas?

Yes.

Because I've been able to implement visitor pattern which is a kind of double dispatch. Of course it's not implemented like the example posted by the OP, but more like a simulation explained in http://en.wikipedia.org/wiki/Double_dispatch wikipedia .

Exactly, it's an emulation: achieves the same effect without availability of double dispatch.

Jonas

Marco van de Voort
to leledumbo: compile time). Are you sure, Jonas? Because I've been able to implement visitor pattern…

In our previous episode, leledumbo said:

Show quoted text 7 lines
> No, because overloading works the same as in C++ (determined statically at compile time). Are you sure, Jonas? Because I've been able to implement visitor pattern which is a kind of double dispatch. Of course it's not implemented like the example posted by the OP, but more like a simulation explained in http://en.wikipedia.org/wiki/Double_dispatch wikipedia .

That is purely statically typed based overloading as far as I can see, and doesn't switch only escape that I know to statically typed calling in FPC is IDispatch.