Mixins 可以在 DynamicProxy 中使用它与类交互吗?
使用拦截器是 mixin 与调用类其他 mixin 交互的唯一方法吗?
我想做如下的事情。
PsuedoCode
class speak
void Greet()
{ Console.WriteLine("Greetings! My Name is " + self.firstname); }
class person
string firstname;
SpeakingPersonProxy = MixIn(person,speak);
SpeakingPersonProxy.firstname = "Noneya"
SpeakingPersonProxy.Greet() //produces Greetings! My name is Noneya
self.firstname(或类似的东西)会以某种方式指向使用greet的类,而不是speak类。 Ruby 有类似的概念,这对于动态语言来说是有意义的。想知道如何在 DynamicProxy 中实现这一点。
Is using Interceptors the only way for a mixin to interact with the calling class other mixins?
I'm looking to do something like below.
PsuedoCode
class speak
void Greet()
{ Console.WriteLine("Greetings! My Name is " + self.firstname); }
class person
string firstname;
SpeakingPersonProxy = MixIn(person,speak);
SpeakingPersonProxy.firstname = "Noneya"
SpeakingPersonProxy.Greet() //produces Greetings! My name is Noneya
self.firstname(or something like it) would somehow point to class using greet, instead of the speak class. Ruby has a similar concept, which makes sense for a dynamic language. Was wondering how to achieve this in DynamicProxy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有任何内置的东西,但是是什么阻止了你:
所以换句话说,如果
speak
hsa要了解它的目标,那就要明确。There's nothing built in, but what's stopping you from:
so in other words, if the
speak
hsa to know about its target, be explicit.