Replies: 1 comment 2 replies
-
What you appear to be suggesting is an operator that allows implicit casting to its own super class, which then returns a different instance. My first intuition is that this sounds like problems. Secondly, this would require some funky dynamic superclassing structure which afaik is fixed after compile time in any typical polymorphism-supporting language, so by my understanding that would require a deep overhaul of the language. It may not even be possible to be consistent from a theoretical point of view. To address the triviality you mention: inheritance is not necessarily usable here. If say T is a sealed type, this would not work. This would therefore also be a problem of enabling the dynamic extension of sealed types, therefore violating the concept of type sealing. All in all this idea appears to violate some core language design decisions and you are probably better of implementing a proxy pattern |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Assume you've got a wrapper class like:
This could be used like:
this has the downside, that you'd always have to call
.Wrapped
to access the actual stuff. Wheras MyWrapper could - trivially - implement T by passing everything to the Wrapped object.for example:
note: that this might make more sense, considering that the Wrapped property might have logic in it's getter/setter.
Edit: to have a bit more clarification:
Imagine you've got an Service class (implementing IService) you want to wrap within a Logging Proxy. IService has far more than 1 method.
to create your logging proxy, you'd create a class like:
now imagine you could SKIP all the trivial IService implementation stuff like i did with "// ...." but have the compiler add the stuff for you. e.g. by using
public class MyServiceLoggingProxy : IService => GetRealService
which instructs it to implement IService by forwarding everything to the member "GetRealService"Beta Was this translation helpful? Give feedback.
All reactions