This post originated from an RSS feed registered with .NET Buzz
by Jonathan Crossland.
Original Post: A Tale of Two Types
Feed Title: Jonathan Crossland Weblog
Feed URL: http://www.jonathancrossland.com/syndication.axd
Feed Description: Design, Frameworks, Patterns and Idioms
I would really like to see Design Patterns merge and disappear into our frameworks and runtimes.
For example, A Singleton could easily become a keyword and managed by the runtime.
But specifically here are two scenarios for merging a wrapper, or form of adaptor pattern.
Mapping Types
If you reference an Assembly (A) from your application that contains a Type that you want to use. Then you discover another Assembly (B), which references (A) you can. However, if the Assembly (B) and the Assembly (A) both reference the same Type from let's say a webservice, the code generated, thinks of these as two different Types. Although they come from the same WCF, or web service, they are treated as different. So creating an AssemblyA.Type and passing it to AssemblyB.Method wont work, as the Types are different. (no they are not). What if I could reference both Assemblies and interchange the two Types as if they were the same. Mark it as the same, and the CLR creates an adaptor/proxy for you.
Now if you have a system, and I have a system, both with a Person object, and happily coincidence it looks exactly the same. Albeit different assemblies, differently signed, it effectively could be the same thing, if only our tools allowed it. So what about being able to explicitly mark the two types so that it can be treated the same. A Wrapper within the CLR
yes we can code this manually
But it is not magically done, and that would save a lots of time. Take how .NET generates COM wrappers. Would you want to write it yourself?
In fact, add Duck Typing to this, method mapping, as explicit choices, a developer can make. Mark the fact, declare that "treat these two classes as the same".
Is this not in effect dynamic partial classes vs the traditional static partial class syntax we have now?