Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
class BaseButton { }
interface IClickable { event Action Click; }
interface IColored { Color Color { get; set; } }
interface ITextContaining { string Text { get; set; } }
class CoolButton : BaseButton, IClickable, IColored, ITextContaining
{
// реализует все интерфейсы
}
class MyForm
{
private BaseButton button;
public BaseButton Button
{
get { return button; }
set
{
if(!(value is IColored || !(value is IClickable)))
{
throw new ArgumentException("Button object must be clickable and colored");
}
button = value;
}
}
public Action ButtonClick
{
get
{
return (button as IClickable).Click;
}
}
// [...]
}
class BaseButton : IClickable { ... }
class ColorButton: BaseButton, IColored { ... }
class TextColoredButton ...
C# — «Множественное наследование» в свойстве класса (или параметре функции)