hand first 设计模式 -状态模式
2009-09-17 00:00:00 来源:WEB开发网打包
Java代码
public class PackingStat extends BuyStat {
private Shop shop;
public PackingStat(Shop shop) {
this.shop = shop;
}
@Override
public void packing() {
// TODO Auto-generated method stub
if (shop.isHasMer()) {
System.out.println("time is packing");
shop.setStat(shop.getWinnerStat());
//清空已购商品状态
shop.setHasMer(false);
} else {
System.out.println("don't packing,so your not merchandise");
shop.setStat(shop.getInShopStat());
}
}
@Override
public void pay() {
// TODO Auto-generated method stub
System.out.println("pay is end");
}
@Override
public void select() {
// TODO Auto-generated method stub
System.out.println("don't select merchandise");
}
}
抽奖
Java代码
public class WinnerStat extends BuyStat {
Random random = new Random();
private Shop shop;
public WinnerStat(Shop shop) {
this.shop = shop;
}
@Override
public void packing() {
// TODO Auto-generated method stub
System.out.println("your merchandise been packing");
}
@Override
public void pay() {
// TODO Auto-generated method stub
System.out.println("your merchandise been pay");
}
@Override
public void select() {
// TODO Auto-generated method stub
System.out.println("don't select merchandise");
}
@Override
public void winner() {
// TODO Auto-generated method stub
int num = random.nextInt(10);
if (num == 8) {
System.out.println("you are a winner");
} else {
System.out.println("sorry,you are not winner");
}
//初始化
shop.setStat(shop.getInShopStat());
}
}
- ››设计模式:工厂方法模式
- ››设计模式一 - Simple Factory, Factory Method, A...
- ››设计模式重构应用---Decorator模式
- ››设计模式重构应用---Template Method模式
- ››hand first 设计模式 - 装饰者模式
- ››hand first 设计模式 - 工厂模式
- ››hand first 设计模式 - 抽象工厂模式
- ››hand first 设计模式 - 单例模式
- ››hand first 设计模式 - 命令模式
- ››hand first 设计模式 -适配器模式
- ››hand first 设计模式 -外观模式
- ››hand first 设计模式 -模板方法模式
更多精彩
赞助商链接