访问者模式中元素的访问级别
在 访问者模式中,我希望客户端只能访问元素的 getter,而访问者应该能够访问 getter 和 setter。你会如何实施它?
我不希望访问者与模型位于同一个包中(已经有很多类)。 我正在考虑引入 IWriteable 接口,其中包含设置器和接受方法。 有更好的办法吗?
谢谢
In the visitor pattern, i want the client to only have access to the getters of the elements, while the visitors should have access to getters and setters. How would you implement it?
I don't want the visitors in the same package as the model (there are a lot of classes already).
I was thinking about introducing IWriteable interface which contains setters and accept methods.
Is there a better way?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@Angel O'Sphere:
该包将包含模型、访问者和工厂所有〜2x(接口和实现)。
我也对流氓程序员有一些想法,这就是我问的原因。
另一种方法是:
但是这种方法有很多缺点,并且如果没有生成技术就很麻烦:o
@Angel O'Sphere:
The package would contains models, visitors and factories all that ~2x (interfaces and impls).
I had some thought about rogue programmer too, that's why I asked.
Another approach would be:
But this approach has many drawbacks and is cumbersome without generative techniques :o