By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Dynamic Proxy in C++

P: n/a
C++ers,

I have programmed in C++ since 1991 and I probably created my best
abstraction layers in C++ in those days. Since 2001 I've been
programming in Java (at first against my will, then I realized the
market was moving into Java) and I'm trying to reimplement in Java
what I did back in those days.

The problem I have is that I have a job offer for programming in C++,
again!!!, and I don't know if I should take it. My problem is mainly
that I use to program using Dynamic proxies in Java, and the mere idea
of going back in time on that technology makes me feel very uneasy and
worrying that I will spend many years writing code that could be
written in months.

In short, is there a mechanism in C++ that is similar to the Dynamic
Proxy mechanism?

If you don't know what a dynamic proxy is, it is simply an interceptor
class that performs some code before and after any method of the
intercepted class, given by the interceptor class. The dynamic proxy
is like a normal proxy, except that a normal proxy must be rewritten
for each intercepted class, while the dynamic proxy is written pnly
once and reused for all intercepted classes.

http://java.sun.com/j2se/1.3/docs/gu...ion/proxy.html

It can be used for logging, for returning resources (like
connections), for validating inputs, for converting normal classes
into EJBs (so remoting them and making them implicitly transactional),
etc.

Cheers,
Guillermo.

Jun 12 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Guillermo Schwarz <gu***************@gmail.comwrote:
In short, is there a mechanism in C++ that is similar to the Dynamic
Proxy mechanism?

If you don't know what a dynamic proxy is, it is simply an interceptor
class that performs some code before and after any method of the
intercepted class, given by the interceptor class. The dynamic proxy
is like a normal proxy, except that a normal proxy must be rewritten
for each intercepted class, while the dynamic proxy is written pnly
once and reused for all intercepted classes.

http://java.sun.com/j2se/1.3/docs/gu...ion/proxy.html

It can be used for logging, for returning resources (like
connections), for validating inputs, for converting normal classes
into EJBs (so remoting them and making them implicitly transactional),
etc.
Maybe this paper will be of interest to you:

Wrapping C++ Member Function Calls
by Bjarne Stroustrup
http://www.research.att.com/~bs/wrapper.pdf

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jun 12 '07 #2

P: n/a
Marcus Kwok wrote:
Guillermo Schwarz <gu***************@gmail.comwrote:
>In short, is there a mechanism in C++ that is similar to the Dynamic
Proxy mechanism?

If you don't know what a dynamic proxy is, it is simply an interceptor
class that performs some code before and after any method of the
intercepted class, given by the interceptor class. The dynamic proxy
is like a normal proxy, except that a normal proxy must be rewritten
for each intercepted class, while the dynamic proxy is written pnly
once and reused for all intercepted classes.

http://java.sun.com/j2se/1.3/docs/gu...ion/proxy.html

It can be used for logging, for returning resources (like
connections), for validating inputs, for converting normal classes
into EJBs (so remoting them and making them implicitly transactional),
etc.

Maybe this paper will be of interest to you:

Wrapping C++ Member Function Calls
by Bjarne Stroustrup
http://www.research.att.com/~bs/wrapper.pdf
unfortunately, i don't think a dynamic solution is possible in c++, not
having reflection mechanisms...

Regards,
Zeppe
Jun 12 '07 #3

P: n/a
Guillermo Schwarz wrote:
... the mere idea
of going back in time on that technology makes me feel very uneasy and
worrying that I will spend many years writing code that could be
written in months.
This should answer your question.

C++ has many features, some that map the same way Java does some that
don't. If you're looking for Java, go find a Java job.
Jun 12 '07 #4

P: n/a
Guillermo Schwarz wrote:
C++ers,

I have programmed in C++ since 1991 and I probably created my best
abstraction layers in C++ in those days. Since 2001 I've been
programming in Java (at first against my will, then I realized the
market was moving into Java) and I'm trying to reimplement in Java
what I did back in those days.

The problem I have is that I have a job offer for programming in C++,
again!!!, and I don't know if I should take it. My problem is mainly
that I use to program using Dynamic proxies in Java, and the mere idea
of going back in time on that technology makes me feel very uneasy and
worrying that I will spend many years writing code that could be
written in months.

In short, is there a mechanism in C++ that is similar to the Dynamic
Proxy mechanism?

If you don't know what a dynamic proxy is, it is simply an interceptor
class that performs some code before and after any method of the
intercepted class, given by the interceptor class. The dynamic proxy
is like a normal proxy, except that a normal proxy must be rewritten
for each intercepted class, while the dynamic proxy is written pnly
once and reused for all intercepted classes.

http://java.sun.com/j2se/1.3/docs/gu...ion/proxy.html

It can be used for logging, for returning resources (like
connections), for validating inputs, for converting normal classes
into EJBs (so remoting them and making them implicitly transactional),
etc.
As C++ offers no reflection, you have to find a solution to this for yourself.

We have written a small tool that generates proxy classes (actually proxy
templates) for COM interfaces. These proxy classes map the COM types to C++
types (like VARIANT_BOOL to bool), so that the user can call COM methods just
like C++ interfaces (thus avoiding the mess with COM return arguments). The
generated proxies look quite similiar to the ones that are generated by Visual C
when you #import a type library, except that logging facilities are added. As
this tool only has to deal with COM interfaces (and only very well-formed COM
interfaces that are Automation compatible), we didn't have to spend to much time
for the mapping of all possible C++ types. This tool is made part of the
compilation process, so we don't have to care much about it.

Another solution would be to provide some kind of reflection feature yourself.
As this seems to be quite challenging, I'd suggest to write your own tool.

Regards,
Stuart
Jun 13 '07 #5

P: n/a
On Jun 12, 2:57 pm, ricec...@gehennom.invalid (Marcus Kwok) wrote:
Guillermo Schwarz <guillermo.schw...@gmail.comwrote:
In short, is there a mechanism in C++ that is similar to the Dynamic
Proxy mechanism?
If you don't know what a dynamic proxy is, it is simply an interceptor
class that performs some code before and after any method of the
intercepted class, given by the interceptor class. The dynamic proxy
is like a normal proxy, except that a normal proxy must be rewritten
for each intercepted class, while the dynamic proxy is written pnly
once and reused for all intercepted classes.
http://java.sun.com/j2se/1.3/docs/gu...ion/proxy.html
It can be used for logging, for returning resources (like
connections), for validating inputs, for converting normal classes
into EJBs (so remoting them and making them implicitly transactional),
etc.

Maybe this paper will be of interest to you:

Wrapping C++ Member Function Calls
by Bjarne Stroustruphttp://www.research.att.com/~bs/wrapper.pdf

--
Marcus Kwok
Replace 'invalid' with 'net' to reply- Hide quoted text -

- Show quoted text -
Very interesting, thanks, Marcus!

Jun 15 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.