就像这样的
这种的设计模式,先写什么后写什么,
求大神帮我罗列书详细步骤图,我是个新手,
所以比较蒙,感谢各位大神了,或者有类似的代码也可以。
------------十分感谢你们的帮助
public abstract class Home
{
public string description = "空房子";
public abstract string getDescription();
public Double Area;
public abstract Double getArea();
}
//房子
public class House : Home
{
public House()
{
description = "MyHouse:";
}
public override string getDescription()
{
return description;
}
public override Double getArea()
{
return 0.0;
}
}
//主卧
public class MainCell : Home
{
Home home;
public MainCell(Home home,Double area)
{
this.home = home;
this.Area = area;
}
public override string getDescription()
{
return this.home.getDescription() + " MainCell";
}
public override Double getArea()
{
return this.Area + home.getArea();
}
}
//阳台
public class Balcony : Home
{
Home home;
public Balcony(Home home, Double area)
{
this.home = home;
this.Area = area;
}
public override string getDescription()
{
return this.home.getDescription() + " Balcony";
}
public override Double getArea()
{
return this.Area + home.getArea();
}
}
采用装饰者模式,添加主卧装饰类,次卧装饰类,客厅装饰类,厨房装饰类,卫生间装饰类,阳台装饰类,根据需要进行装饰即可。
有没有人啊 这回答的具体一下子
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!
public abstract class Home
{
public string description = "空房子";
public abstract string getDescription();
public Double Area;
public abstract Double getArea();
}
//房子
public class House : Home
{
public House()
{
description = "MyHouse:";
}
public override string getDescription()
{
return description;
}
public override Double getArea()
{
return 0.0;
}
}
//主卧
public class MainCell : Home
{
Home home;
public MainCell(Home home,Double area)
{
this.home = home;
this.Area = area;
}
public override string getDescription()
{
return this.home.getDescription() + " MainCell";
}
public override Double getArea()
{
return this.Area + home.getArea();
}
}
//阳台
public class Balcony : Home
{
Home home;
public Balcony(Home home, Double area)
{
this.home = home;
this.Area = area;
}
public override string getDescription()
{
return this.home.getDescription() + " Balcony";
}
public override Double getArea()
{
return this.Area + home.getArea();
}
}
//测试代码
//创建一个空房子,初期面积0
Home myHouse = new House();
//在房子上装饰一个主卧
myHouse = new MainCell(myHouse, 20);
//在房子上装饰一个主卧
myHouse = new MainCell(myHouse, 20);
//在房子上装饰一个阳台
myHouse = new Balcony(myHouse, 15);
Console.WriteLine(myHouse.getDescription());
Console.WriteLine("Area:" + myHouse.getArea());
//输入结果
MyHouse: MainCell MainCell Balcony
Area:55