具有代理设计模式的预处理器
在代理部分,四人帮的设计模式说:
重载成员访问运算符并不是适合每种代理的良好解决方案。一些代理 需要准确地知道调用了哪个操作,并重载了成员访问运算符 在这些情况下不起作用。
[...]
在这种情况下我们必须手动 实现将请求转发给主题的每个代理操作。
[...]
通常 所有操作在转发之前都会验证请求是否合法、原始对象是否存在等 对主题的请求。一遍又一遍地编写这段代码是很乏味的。因此,通常使用预处理器自动生成它。
好的,C++ 中使用哪种预处理器以及如何处理?
In the proxy section the Design Patter from the Gang of Four says:
Overloading the member access operator isn't a good solution for every kind of proxy. Some proxies
need to know precisely which operation is called, and overloading the member access operator
doesn't work in those cases.[...]
In that case we must manually
implement each proxy operation that forwards the request to the subject.[...]
Typically
all operations verify that the request is legal, that the original object exists, etc., before forwarding
the request to the subject. It's tedious to write this code again and again. So it's common to use a preprocessor to generate it automatically.
OK, which preprocessor and how in C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 C++ 中实现某些设计模式的规范参考是
关于使用 C++ 类型系统构建设计模式的技术的另一本很好的参考书是
模板元编程的参考是
The canonical reference for implementing some Design Patterns in C++ is
Another good reference for the techniques of using the type system of C++ for building design patterns is the book on
And the reference for template meta-programming is
我认为它们的意思是围绕主题类自动生成包装器代码。一个示例是 SWIG 项目生成的包装器代码。
I think they mean automated generation of the wrapper code around the subject class. An example would be wrapper code generated by the SWIG project.