- package designpattern.state;
- public class Food {
- private String name;
- private int manufactureDays;// 出厂天数
- private int bestBeforeDays;// 最佳食用天数(从出厂时间算起)
- private int expiryDays;// 保质期天数
- private FoodState foodState;
- public Food(String name, int bestBeforeDays, int expiryDays) {
- this.name = name;
- this.bestBeforeDays = bestBeforeDays;
- this.expiryDays = expiryDays;
- this.foodState = new BestBeforeState();
- }
- public void eat() {
- foodState.reaction(this);
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getManufactureDays() {
- return manufactureDays;
- }
- public void setManufactureDays(int manufactureDays) {
- this.manufactureDays = manufactureDays;
- }
- public int getBestBeforeDays() {
- return bestBeforeDays;
- }
- public void setBestBeforeDays(int bestBeforeDays) {
- this.bestBeforeDays = bestBeforeDays;
- }
- public int getExpiryDays() {
- return expiryDays;
- }
- public void setExpiryDays(int expiryDays) {
- this.expiryDays = expiryDays;
- }
- public FoodState getFoodState() {
- return foodState;
- }
- public void setFoodState(FoodState foodState) {
- this.foodState = foodState;
- }
- }