Note that there are some explanatory texts on larger screens.

plurals
  1. POLinFu - can't quite see how to do what I want
    primarykey
    data
    text
    <p>Just found LinFu - looks very impressive, but I can't <em>quite</em> see how to do what I want to do - which is multiple inheritance by mixin (composition/delegation as I'd say in my VB5/6 days - when I had a tool to generate the tedious repetitive delegation code - it was whilst looking for a C# equivalent that I found LinFu).</p> <p>FURTHER EDIT: TO clarify what I mean by composition/delegation and mixin. </p> <pre><code>public class Person : NEOtherBase, IName, IAge { public Person() { } public Person(string name, int age) { Name = name; Age = age; } //Name "Mixin" - you'd need this code in any object that wanted to //use the NameObject to implement IName private NameObject _nameObj = new NameObject(); public string Name { get { return _nameObj.Name; } set { _nameObj.Name = value; } } //-------------------- //Age "Mixin" you'd need this code in any object that wanted to //use the AgeObject to implement IAge private AgeObject _ageObj = new AgeObject(); public int Age { get { return _ageObj.Age; } set { _ageObj.Age = value; } } //------------------ } public interface IName { string Name { get; set; } } public class NameObject : IName { public NameObject() {} public NameObject(string name) { _name = name; } private string _name; public string Name { get { return _name; } set { _name = value; } } } public interface IAge { int Age { get; set; } } public class AgeObject : IAge { public AgeObject() {} public AgeObject(int age) { _age = age; } private int _age; public int Age { get { return _age; } set { _age = value; } } } </code></pre> <p>Imagine objects with many more properties, used in many more "subclasses" and you start to see the tedium. A code-gernation tool would actually be just <em>fine</em>...</p> <p>So, LinFu.... The mixin example below is fine but I'd want to have an actual Person <em>class</em> (as above) - what's the LinFu-esque way of doing that? Or have I missed the whole point? </p> <p>EDIT: I need to be able to do this with classes that are already subclassed.</p> <pre><code>DynamicObject dynamic = new DynamicObject(); IPerson person = null; // This will return false bool isPerson = dynamic.LooksLike&lt;IPerson&gt;(); // Implement IPerson dynamic.MixWith(new HasAge(18)); dynamic.MixWith(new Nameable("Me")); // Now that it’s implemented, this // will be true isPerson = dynamic.LooksLike&lt;IPerson&gt;(); if (isPerson) person = dynamic.CreateDuck&lt;IPerson&gt;(); // This will return “Me” string name = person.Name; // This will return ‘18’ int age = person.Age; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload