public void Handle(Environmental environmental) { //房屋出租 if (environmental._statePattern.State == HouseState.Lease) { Console.WriteLine($"{environmental._statePattern.Name}房屋正在出租!"); Console.WriteLine("如果觉得可以的话就签订租房合同!"); environmental.SetState(new LeaseedState()); environmental.Show(); } }
public void Handle(Environmental environmental) { //后期办理退房手续 if (environmental._statePattern.State == HouseState.Lease) { Console.WriteLine($"{environmental._statePattern.Name}签订租房合同!"); environmental._statePattern.State = HouseState.Leaseed; environmental._statePattern.Time = 1; environmental.SetState(new DepositState()); environmental.Show(); } }
public void Handle(Environmental environmental) { environmental._statePattern.IsDeposit = true; if (environmental._statePattern.State == HouseState.Leaseed && environmental._statePattern.Time < 6) { Console.WriteLine($"{environmental._statePattern.Name}如果现在退房的话是不能退押金的!"); environmental._statePattern.IsDeposit = false; } else { Console.WriteLine($"{environmental._statePattern.Name}如果现在退房的话是可以退押金的!"); } Console.WriteLine("考虑是否退房!"); }
static void Main(string[] args) { //初始化房源信息 List <StatePattern> statePatterns = new List <StatePattern>(); statePatterns.Add(new StatePattern { Id = 1, Name = "房屋一", State = HouseState.Lease }); Environmental environmental = new Environmental(); //房屋一出租 environmental.GetStatePattern(statePatterns.Where(x => x.Id == 1).FirstOrDefault()); environmental.Show(); //时间大于半年可退押金 statePatterns[0].Time = 7; environmental.Show(); }