views:

66

answers:

1

Possible Duplicate:
Multiple Inheritance in C#

In the following example, I want the Shirt to automatically inherit the properties of both the Material and Pigment classes. Is this even possible in C#?

public class Material
{
    public enum FabricTypes { Cotton, Wool, Polyester, Nylon }
    public FabricTypes Fabric { get; set; }
    public Color Color { get; set; }
}

public class Pigment
{
    public enum PigmentQualities { Fine, Average, Poor }
    public PigmentQualities Quality { get; set; }
    public Color Color { get; set; }
}

public class Shirt : Material //, Pigment
{
    public Shirt()
    {
        Fabric = FabricTypes.Cotton;
        Color = new Color();
        //Quality = PigmentQualities.Fine;
    }
}

I'm having a hard time furnishing a better example, but this is essentially what I'm trying to do. I realize I can create interfaces, but those won't automatically inherit the properties. See, because I don't want to have to manually punch in all those properties every time I create a class that is similar to Shirt.

+1  A: 

C# doesn't allow to inherit from multiple classes.

But why do you do it like this? Shirt could have 2 properties instead: Material and Pigment. Those could be set when you initialize a Shirt instance like passing it in a constructor with those properties set. Or create a constructor in which you can pass certain properties and instantiate Material and Pigment in that constructor.

XIII
The reason why I do this is because my scenario involves many more properties than you see in this simple example, from many different classes. Furthermore? There are going to be over 100 `Shirt` classes in my real-world scenario and I can't imagine typing all the same properties for these or even from an interface. It just seems like too much work. I thought there might be a better way—something I'm missing?
sfjedi
100 Shirt different classes? I would expect only 1 but 100 instantiations of the Shirt class.
XIII
No, no... I mean... 100+ classes that are similar to Shirt, in that they need to inherit multiple properties from other classes.
sfjedi
The problem is that in the real-world scenario, Material and Pigment will have probably 20 properties inside of them. I'm trying to break it down here into the most simple elements. Why does nobody ever understand that? I don't want to post like 300 lines of code and have you guys try to decipher it. This is the core thing I'm trying to do.
sfjedi