面向对象设计与分析的一个小问题.
本人菜鸟,说错了的,请指教.
一个很简单的功能,但是要遵循面向对象原则,现在能实现的是按下按钮,如果门是开的,则关上,如果是关的,则打开,但是现在需要这样:"门是开的,则关上,如果是关的,则打开"这里相同,但是,打开门口,隔10秒,门会自动关闭,.!
一下是现功能代码,表达的不是很好,.
DogDoor.cs:
namespace DogDoor
{
public class DogDoor
{
public static Boolean open;
public DogDoor()
{
//
}
public bool toOpen()
{
open = true;
return open;
}
public bool toClose()
{
open = false;
return open;
}
public Boolean isOpen()
{
return open;
}
}
}
Remote.cs:
public class Remote
{
private DogDoor door;
public Remote(DogDoor door)
{
this.door = door;
}
public bool pressButton()
{
if (door.isOpen() == true)
{
return this.door.toClose();
}
else
{
return this.door.toOpen();
}
}
}
下面是页面代码:
public partial class DoorTest : System.Web.UI.Page
{
DogDoor door = new DogDoor();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{