Proposal: Composite Implementation Routing #2017
-
Composition is a powerful tool in object oriented design, but I'm somewhat bothered by having to reroute the interface members to implementation members, which are usually one-on-one calls. I'm thinking about a C# language proposal to alleviate this burden and I'm posting here to discuss as to whether this might be a good idea. The code is as follows: NAME: COMPOSITE IMPLEMENTATION ROUTING
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Looks like mostly a duplicate of #900, just with a slightly different syntax. |
Beta Was this translation helpful? Give feedback.
-
Looks more like a duplicate of #234 (with different syntax) to me. |
Beta Was this translation helpful? Give feedback.
-
C# 9.0 Source generators should make it possible to write something like this: public partial class MyCompositeClass
{
[ImplementInterface]
protected IComposite1 _composite1;
[ImplementInterface(typeof(IComposite2))]
private Composite2Impl _composite2;
public MyCompositeClass(IComposite1 composite1)
{
_composite1 = composite1;
_composite2 = new Composite2Impl();
}
} and have the source generator generate the rest. |
Beta Was this translation helpful? Give feedback.
-
Note that Visual Studio has a refactoring to insert all of the boilerplate for you, as well. If you write: public class MyCompositeClass : IComposite1
{
private IComposite1 _composite1;
public MyCompositeClass(IComposite1 composite1)
{
_composite1 = composite1;
}
} Then put your cursor over |
Beta Was this translation helpful? Give feedback.
C# 9.0 Source generators should make it possible to write something like this:
and have the source generator generate the rest.