Extending gcjx visitor pattern

Cédric Berger cedric@berger.to
Tue Dec 6 10:54:00 GMT 2005


Ranjit Mathew wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Mike Emmel wrote:
>> I was wondering what people would think about extending the gcjx
>> visitor to also forward
>> user data.
>>
>> I.e visit_method (model_method * method,
>>                 const list<ref_variable_decl> & params,
>>                 const ref_block &block)
>>
>> would becomes
>>
>> visit_method (model_method * method,
>>                 const list<ref_variable_decl> & params,
>>                 const ref_block &block, void * visitorData );
>
> If I understand you correctly, you want the Visitor to
> say:
>
>   someObject->visit (this, opaqueBlob);
>
> and then the visited object (Visitee?) to call back
> the appropriate visit_snafu() method like:
>
>   visitorObject->visit_snafu (this, foo, bar, opaqueBlob);
>
> Right?
That's certainly the way most people implement these kind of things
int the C language, so you don't need to put your context data
(opaqueBlob) on global or thread-local memory, which is very unclean
and error-prone.

But in the OO case, you can just attach the context data inside the
visitorObject, which, if I understand correctly, is forwarded across
all the call tree. Anonymous subclasses of visitorObject might be
handy.

Cedric



More information about the Java mailing list