EDN Admin
Well-known member
<span>
<span style="text-decoration:underline Disclaimer :
First things first, a word of caution. Multiple inheritance is not possible in C#, and theres a good reason for it. I just wrote up this post to share some code and some ideas I had, youre absolutely free not to like it and not to use it. Im not even
claiming this idea is the "answer to all of lifes problems", or even "useful to you in any way". And Im absolutely not trying to defend the idea of multiple inheritance. However as usual, any constructive critique, additions, thoughts, ... are more then
appreciated. Please don not assume the code samples (tight coupling, bad naming, ...) are in any way representative for the way I write code. They just help me demonstrate the idea.
If you like this work, feel free to click the "was helpful" button, free credit towards my fourth star on the MSDN forums is always appreciated.
<span style="text-decoration:underline Why use implicit composition?
Junior year of college, just getting started into OOP, weve all learned about inheritance. Its great, but there are many pitfalls.
Lets have a look at some sample code, nothing too fancy...
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue interface IPushable { <span style="color:blue void Push(); }
<span style="color:blue public <span style="color:blue class Pushable : IPushable { <span style="color:blue public <span style="color:blue void Push(){ Console.WriteLine(<span style="color:#a31515 "Pushed a pushable!"); } }
<span style="color:blue public <span style="color:blue class Button : Pushable
{
<span style="color:blue public Button() : <span style="color:blue base() { }
}
<span style="color:blue class Program {
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args) {
Button button = <span style="color:blue new Button();
TryPushingIt(button);
Console.ReadKey(<span style="color:blue true);
}
<span style="color:blue static <span style="color:blue void TryPushingIt(IPushable pushable) { pushable.Push(); }
}
[/code]
Nothing too fancy here, theres an interface IPushable, a basic implementation Pushable, and a little testprogram. The program creates a new Button, and passes it to the TryPushIt method. This works because Button IS a Pushable. (Inheritance).
Not too soon after, the inheritance design you used gets improved when you learn about composition. The sample code above could (should) be rewritten to use composition like this:
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue interface IPushable { <span style="color:blue void Push(); }
<span style="color:blue public <span style="color:blue class Pushable : IPushable { <span style="color:blue public <span style="color:blue void Push(){ Console.WriteLine(<span style="color:#a31515 "Pushed a pushable!"); } }
<span style="color:blue public <span style="color:blue class Button : IPushable {
<span style="color:blue public Button() : <span style="color:blue base() { }
<span style="color:blue private IPushable pushable = <span style="color:blue new Pushable();
<span style="color:blue public <span style="color:blue void Push() { <span style="color:blue this.pushable.Push(); }
}
<span style="color:blue class Program{
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args) {
Button button = <span style="color:blue new Button();
TryPushingIt(button);
Console.ReadKey(<span style="color:blue true);
}
<span style="color:blue static <span style="color:blue void TryPushingIt(IPushable pushable) { pushable.Push(); }
}
[/code]
Still nothing new here (hopefully), theres an interface IPushable, a basic implementation Pushable, and a little testprogram. The program creates a new Button, and passes it to the TryPushIt method. This works because Button HAS a Pushable, and forwards
the method calls to it. (Composition).
However, having done this kind of composition a thousand times and more, Im getting kind of fed up with the amount of (what I call) boiler template code, required to make the composition work, which was not required when using inheritance. For clarity,
Im talking about this code being added to my Button class:
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue private IPushable pushable = <span style="color:blue new Pushable();
<span style="color:blue public <span style="color:blue void Push() { <span style="color:blue this.pushable.Push(); }
[/code]
Sure in our example, Button is composed out of just one part (Pushable), and has just one method call to forward (Push). However, classes can be composed out of multiple parts, each with a couple of methods, quickly increasing the amount of boiler template
code. More code not only means more work to make it work, but also more chance to introduce bugs by subtle typing errors (especially when the composed parts have methods that are heavily overloaded, being dyslectic, speaking out of personal experience here).
Thats the problem, I was trying to solve...
<span style="text-decoration:underline So what is implicit composition?
Playing around a bit, trying to find a way to reduce the amount of code needed to do composition, Ive come up with this base class, using generics to replace the boiler plate code I mentioned.
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class ImplicitlyComposed<T>{
<span style="color:blue private T t;
<span style="color:blue public ImplicitlyComposed(T t) { <span style="color:blue this.t = t; }
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T> comp) { <span style="color:blue return comp.t; }
}
[/code]
The class consist out of a composition part (the first two lines), and an implicit cast from the class to the composed part. (Hence the name: Implicit Composition).
Lets rewrite our code sample to use this base class...
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue interface IPushable { <span style="color:blue void Push(); }
<span style="color:blue public <span style="color:blue class Pushable : IPushable { <span style="color:blue public <span style="color:blue void Push(){ Console.WriteLine(<span style="color:#a31515 "Pushed a pushable!"); } }
<span style="color:blue public <span style="color:blue class Button : ImplicitlyComposed<Pushable> {
<span style="color:blue public Button() : <span style="color:blue base(<span style="color:blue new Pushable()) { }
}
<span style="color:blue class Program {
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args) {
Button button = <span style="color:blue new Button();
TryPushingIt(button);
Console.ReadKey(<span style="color:blue true);
}
<span style="color:blue static <span style="color:blue void TryPushingIt(Pushable pushable) { pushable.Push(); }
}
[/code]
Again, nothing really mind blowing in this code sample, theres an interface IPushable, a basic implementation Pushable, and a little testprogram. The program creates a new Button, and passes it to the TryPushIt method. This works because Button CAN BE CAST
TO a Pushable. (Implicit Composition).
Because this cast is implicit, theres really not much code needed to compose Button out of a Pushable, only the declaration at the top ("Button : ImplicitlyComposed<Pushable>"), compared to the solution using inheritance, and theres substantially
less code needed compared to the code sample using composition.
<span style="text-decoration:underline But what about multiple composition?
Inheritance you can do, multiple inheritance is a no-no. (In c# that is.)
Composition you can do, and so is composing a class out of multiple parts.
When trying to reduce the code needed for composition, being able to support multiple parts is a requirement as well. Have a look at what I came up with to solve this:
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class ImplicitlyComposed<T> {
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t) { <span style="color:blue this.t = t; }
}<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U> : ImplicitlyComposed<U> {
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u) : <span style="color:blue base (u) { <span style="color:blue this.t = t; }
}
[/code]
I have copy&pasted the base class ImplicitlyComposed, and added a new generic type to it. See how fast it is to expand our Button in the example to be composed of multiple parts:
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class Visualisable { <span style="color:blue public <span style="color:blue void Visualise() { Console.WriteLine(<span style="color:#a31515 "Visualized!"); } }
<span style="color:blue public <span style="color:blue class Pushable { <span style="color:blue public <span style="color:blue void Push(){ Console.WriteLine(<span style="color:#a31515 "Pushed a pushable!"); } }
<span style="color:blue public <span style="color:blue class Button : ImplicitlyComposed<Pushable, Visualisable> {
<span style="color:blue public Button() : <span style="color:blue base(<span style="color:blue new Pushable(), <span style="color:blue new Visualisable()) { }
}
<span style="color:blue class Program {
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args){
Button button = <span style="color:blue new Button();
TryPushingIt(button);
TryVisualisingIt(button);
Console.ReadKey(<span style="color:blue true);
}
<span style="color:blue static <span style="color:blue void TryPushingIt(Pushable pushable) { pushable.Push(); }
<span style="color:blue static <span style="color:blue void TryVisualisingIt(Visualisable visualisable){ visualisable.Visualise(); }
}
[/code]
Once again, Im only required to change the class declaration "Button : ImplicitlyComposed<Pushable>" to "Button : ImplicitlyComposed<Pushable, Visualisable>", and I can pass my button as if it was a Pushable, as well as a Visualisable (as if
Im using multiple inheritance), while in fact Button has a Pushable and a Visualisable, and can be implicitly cast to either one.
<span style="text-decoration:underline Any conclusions?
Theres a lot of cons going for this implicit inheritance, like running into the issues as the inheritance diamond, and the fact that it can not be used with interfaces... (Yet...) So I would never use this in a public API as it is.
However, at the very least its been a fun little idea to play with, and Im currently doing a nice project where Im actually enjoying using this very much...
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class ManageCustomerViewModel : ImplicitlyComposed < EntitySelectionViewModel<Customer>, SearchableViewModel<Customer>, AdditionalActionsViewModel<CreateNew<Customer>, ViewBalance, CreateInvoice>>>
[/code]
The above code would be all thats needed to compose my ManageCustomerViewModel out of a list of customers, that can be filtered/searched, where new customers can be created, and for a selected customer, his/her balance can be viewed, or a new invoice can
be created...
<span style="text-decoration:underline Addendum 1:
The greatest flaw in my opinion, is the lack of support for interfaces, because its not possible to create user defined conversions to and from interfaces... Help me improve my design
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/a5268304-6aa2-44f2-b060-7d037316b9ca
here , and/or upvote https://connect.microsoft.com/VisualStudio/feedback/details/318122/allow-user-defined-implicit-type-conversion-to-interface-in-c
this request if you agree with it.
<span style="text-decoration:underline Addendum 2:
Heres the code for the five first ImplicitlyComposed classes. For your own library, feel free to add even more generic types...
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class ImplicitlyComposed<T>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t) { <span style="color:blue this.t = t; }
}
<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U> : ImplicitlyComposed<U>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u) : <span style="color:blue base (u) { <span style="color:blue this.t = t; }
}
<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U, V> : ImplicitlyComposed<U, V>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U, V> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u, V v) : <span style="color:blue base(u, v) { <span style="color:blue this.t = t; }
}
<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U, V, W> : ImplicitlyComposed<U, V, W>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U, V, W> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u, V v, W w) : <span style="color:blue base(u, v, w) { <span style="color:blue this.t = t; }
}
<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U, V, W, X> : ImplicitlyComposed<U, V, W, X>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U, V, W, X> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u, V v, W w, X x) : <span style="color:blue base(u, v, w, x) { <span style="color:blue this.t = t; }
}
[/code]
<
"The improbable we do, the impossible just takes a little longer." (Steven Parker)<br/>
<br/>
<br/>
<br/>
View the full article
<span style="text-decoration:underline Disclaimer :
First things first, a word of caution. Multiple inheritance is not possible in C#, and theres a good reason for it. I just wrote up this post to share some code and some ideas I had, youre absolutely free not to like it and not to use it. Im not even
claiming this idea is the "answer to all of lifes problems", or even "useful to you in any way". And Im absolutely not trying to defend the idea of multiple inheritance. However as usual, any constructive critique, additions, thoughts, ... are more then
appreciated. Please don not assume the code samples (tight coupling, bad naming, ...) are in any way representative for the way I write code. They just help me demonstrate the idea.
If you like this work, feel free to click the "was helpful" button, free credit towards my fourth star on the MSDN forums is always appreciated.
<span style="text-decoration:underline Why use implicit composition?
Junior year of college, just getting started into OOP, weve all learned about inheritance. Its great, but there are many pitfalls.
Lets have a look at some sample code, nothing too fancy...
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue interface IPushable { <span style="color:blue void Push(); }
<span style="color:blue public <span style="color:blue class Pushable : IPushable { <span style="color:blue public <span style="color:blue void Push(){ Console.WriteLine(<span style="color:#a31515 "Pushed a pushable!"); } }
<span style="color:blue public <span style="color:blue class Button : Pushable
{
<span style="color:blue public Button() : <span style="color:blue base() { }
}
<span style="color:blue class Program {
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args) {
Button button = <span style="color:blue new Button();
TryPushingIt(button);
Console.ReadKey(<span style="color:blue true);
}
<span style="color:blue static <span style="color:blue void TryPushingIt(IPushable pushable) { pushable.Push(); }
}
[/code]
Nothing too fancy here, theres an interface IPushable, a basic implementation Pushable, and a little testprogram. The program creates a new Button, and passes it to the TryPushIt method. This works because Button IS a Pushable. (Inheritance).
Not too soon after, the inheritance design you used gets improved when you learn about composition. The sample code above could (should) be rewritten to use composition like this:
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue interface IPushable { <span style="color:blue void Push(); }
<span style="color:blue public <span style="color:blue class Pushable : IPushable { <span style="color:blue public <span style="color:blue void Push(){ Console.WriteLine(<span style="color:#a31515 "Pushed a pushable!"); } }
<span style="color:blue public <span style="color:blue class Button : IPushable {
<span style="color:blue public Button() : <span style="color:blue base() { }
<span style="color:blue private IPushable pushable = <span style="color:blue new Pushable();
<span style="color:blue public <span style="color:blue void Push() { <span style="color:blue this.pushable.Push(); }
}
<span style="color:blue class Program{
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args) {
Button button = <span style="color:blue new Button();
TryPushingIt(button);
Console.ReadKey(<span style="color:blue true);
}
<span style="color:blue static <span style="color:blue void TryPushingIt(IPushable pushable) { pushable.Push(); }
}
[/code]
Still nothing new here (hopefully), theres an interface IPushable, a basic implementation Pushable, and a little testprogram. The program creates a new Button, and passes it to the TryPushIt method. This works because Button HAS a Pushable, and forwards
the method calls to it. (Composition).
However, having done this kind of composition a thousand times and more, Im getting kind of fed up with the amount of (what I call) boiler template code, required to make the composition work, which was not required when using inheritance. For clarity,
Im talking about this code being added to my Button class:
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue private IPushable pushable = <span style="color:blue new Pushable();
<span style="color:blue public <span style="color:blue void Push() { <span style="color:blue this.pushable.Push(); }
[/code]
Sure in our example, Button is composed out of just one part (Pushable), and has just one method call to forward (Push). However, classes can be composed out of multiple parts, each with a couple of methods, quickly increasing the amount of boiler template
code. More code not only means more work to make it work, but also more chance to introduce bugs by subtle typing errors (especially when the composed parts have methods that are heavily overloaded, being dyslectic, speaking out of personal experience here).
Thats the problem, I was trying to solve...
<span style="text-decoration:underline So what is implicit composition?
Playing around a bit, trying to find a way to reduce the amount of code needed to do composition, Ive come up with this base class, using generics to replace the boiler plate code I mentioned.
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class ImplicitlyComposed<T>{
<span style="color:blue private T t;
<span style="color:blue public ImplicitlyComposed(T t) { <span style="color:blue this.t = t; }
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T> comp) { <span style="color:blue return comp.t; }
}
[/code]
The class consist out of a composition part (the first two lines), and an implicit cast from the class to the composed part. (Hence the name: Implicit Composition).
Lets rewrite our code sample to use this base class...
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue interface IPushable { <span style="color:blue void Push(); }
<span style="color:blue public <span style="color:blue class Pushable : IPushable { <span style="color:blue public <span style="color:blue void Push(){ Console.WriteLine(<span style="color:#a31515 "Pushed a pushable!"); } }
<span style="color:blue public <span style="color:blue class Button : ImplicitlyComposed<Pushable> {
<span style="color:blue public Button() : <span style="color:blue base(<span style="color:blue new Pushable()) { }
}
<span style="color:blue class Program {
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args) {
Button button = <span style="color:blue new Button();
TryPushingIt(button);
Console.ReadKey(<span style="color:blue true);
}
<span style="color:blue static <span style="color:blue void TryPushingIt(Pushable pushable) { pushable.Push(); }
}
[/code]
Again, nothing really mind blowing in this code sample, theres an interface IPushable, a basic implementation Pushable, and a little testprogram. The program creates a new Button, and passes it to the TryPushIt method. This works because Button CAN BE CAST
TO a Pushable. (Implicit Composition).
Because this cast is implicit, theres really not much code needed to compose Button out of a Pushable, only the declaration at the top ("Button : ImplicitlyComposed<Pushable>"), compared to the solution using inheritance, and theres substantially
less code needed compared to the code sample using composition.
<span style="text-decoration:underline But what about multiple composition?
Inheritance you can do, multiple inheritance is a no-no. (In c# that is.)
Composition you can do, and so is composing a class out of multiple parts.
When trying to reduce the code needed for composition, being able to support multiple parts is a requirement as well. Have a look at what I came up with to solve this:
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class ImplicitlyComposed<T> {
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t) { <span style="color:blue this.t = t; }
}<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U> : ImplicitlyComposed<U> {
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u) : <span style="color:blue base (u) { <span style="color:blue this.t = t; }
}
[/code]
I have copy&pasted the base class ImplicitlyComposed, and added a new generic type to it. See how fast it is to expand our Button in the example to be composed of multiple parts:
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class Visualisable { <span style="color:blue public <span style="color:blue void Visualise() { Console.WriteLine(<span style="color:#a31515 "Visualized!"); } }
<span style="color:blue public <span style="color:blue class Pushable { <span style="color:blue public <span style="color:blue void Push(){ Console.WriteLine(<span style="color:#a31515 "Pushed a pushable!"); } }
<span style="color:blue public <span style="color:blue class Button : ImplicitlyComposed<Pushable, Visualisable> {
<span style="color:blue public Button() : <span style="color:blue base(<span style="color:blue new Pushable(), <span style="color:blue new Visualisable()) { }
}
<span style="color:blue class Program {
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args){
Button button = <span style="color:blue new Button();
TryPushingIt(button);
TryVisualisingIt(button);
Console.ReadKey(<span style="color:blue true);
}
<span style="color:blue static <span style="color:blue void TryPushingIt(Pushable pushable) { pushable.Push(); }
<span style="color:blue static <span style="color:blue void TryVisualisingIt(Visualisable visualisable){ visualisable.Visualise(); }
}
[/code]
Once again, Im only required to change the class declaration "Button : ImplicitlyComposed<Pushable>" to "Button : ImplicitlyComposed<Pushable, Visualisable>", and I can pass my button as if it was a Pushable, as well as a Visualisable (as if
Im using multiple inheritance), while in fact Button has a Pushable and a Visualisable, and can be implicitly cast to either one.
<span style="text-decoration:underline Any conclusions?
Theres a lot of cons going for this implicit inheritance, like running into the issues as the inheritance diamond, and the fact that it can not be used with interfaces... (Yet...) So I would never use this in a public API as it is.
However, at the very least its been a fun little idea to play with, and Im currently doing a nice project where Im actually enjoying using this very much...
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class ManageCustomerViewModel : ImplicitlyComposed < EntitySelectionViewModel<Customer>, SearchableViewModel<Customer>, AdditionalActionsViewModel<CreateNew<Customer>, ViewBalance, CreateInvoice>>>
[/code]
The above code would be all thats needed to compose my ManageCustomerViewModel out of a list of customers, that can be filtered/searched, where new customers can be created, and for a selected customer, his/her balance can be viewed, or a new invoice can
be created...
<span style="text-decoration:underline Addendum 1:
The greatest flaw in my opinion, is the lack of support for interfaces, because its not possible to create user defined conversions to and from interfaces... Help me improve my design
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/a5268304-6aa2-44f2-b060-7d037316b9ca
here , and/or upvote https://connect.microsoft.com/VisualStudio/feedback/details/318122/allow-user-defined-implicit-type-conversion-to-interface-in-c
this request if you agree with it.
<span style="text-decoration:underline Addendum 2:
Heres the code for the five first ImplicitlyComposed classes. For your own library, feel free to add even more generic types...
<div style="background-color:#ffffcc; color:black
<pre><span style="color:blue public <span style="color:blue class ImplicitlyComposed<T>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t) { <span style="color:blue this.t = t; }
}
<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U> : ImplicitlyComposed<U>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u) : <span style="color:blue base (u) { <span style="color:blue this.t = t; }
}
<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U, V> : ImplicitlyComposed<U, V>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U, V> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u, V v) : <span style="color:blue base(u, v) { <span style="color:blue this.t = t; }
}
<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U, V, W> : ImplicitlyComposed<U, V, W>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U, V, W> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u, V v, W w) : <span style="color:blue base(u, v, w) { <span style="color:blue this.t = t; }
}
<span style="color:blue public <span style="color:blue class ImplicitlyComposed<T, U, V, W, X> : ImplicitlyComposed<U, V, W, X>
{
<span style="color:blue private T t;
<span style="color:blue public <span style="color:blue static <span style="color:blue implicit <span style="color:blue operator T(ImplicitlyComposed<T, U, V, W, X> comp) { <span style="color:blue return comp.t; }
<span style="color:blue public ImplicitlyComposed(T t, U u, V v, W w, X x) : <span style="color:blue base(u, v, w, x) { <span style="color:blue this.t = t; }
}
[/code]
<
"The improbable we do, the impossible just takes a little longer." (Steven Parker)<br/>
<br/>
<br/>
<br/>
View the full article