이 질문은 this one과 비슷합니다. 차이점은 두 개의 기본 클래스를 갖고 싶다는 것입니다.C#에서 유창한 인터페이스와 다중 상속
예 :
public class Circle
{
private string _radius { get; set; }
public Circle Radius(string radius)
{
_radius = radius;
return this;
}
}
public class Box
{
private string _width { get; set; }
public Circle Width(string width)
{
_width = width;
return this;
}
}
public class CircleAndBox : Circle, Box // Can't do in c#
{
// should contain methods from both Circle and Box, but return CircleAndBox
}
아마 원과 상자는 좋은 예 아니었다. 기본적으로 다른 속성과 메서드를 가진 클래스를 나타냅니다. CircleAndBox 클래스는 Circle 및 Box와 동일한 속성 및 메서드를 가지고 있습니다. CircleAndBox에는 Circle이나 Box에 존재하지 않는 추가 속성과 메서드가있을 수 있습니다.
원하는 결과
내가 쓸 수 있어야 :
그것은 것var circle = new Circle().Radius("5");
var box = new Box().Width("6");
var circleAndBox = new CircleAndBox().Radius("5").Width("6");
슈퍼 경우 :
내가 Circle
또는 Box
클래스에 메소드를 추가, I CircleAndBox
클래스를 만지지 않아야합니다. 그냥 하나의 클래스에서 일반 상속과 마찬가지로, CircleAndBox
가 자동으로 모두 Circle
및 Box
인터페이스 인터페이스 인터페이스 ... 둘 모두에 대해 무엇이 필요합니까? 서클 + 상자 란 무엇입니까? 상자 안에 원이 있다면 원 반경이 상자 너비의 절반입니까? – Sayse
'.Width ("6")'?? '.Width ("BigFat")'?? –
'새 CircleAndBox(). 반경 ("5") 너비 ("6");'* 너무 유동적이기 때문에 의미가 무엇인지 이해하지 못합니다. – spender