介绍
根据不同的天气事件,做出不同的操作
事件
事件基类接口
/**
* 事件
* @author silly
*/
public interface Event {
}
定义事件的接口,所有的事件都实现该接口
天气事件
/**
* 天气事件
*
* @author silly
*/
public class WeatherEvent implements Event {
/**
* 当前温度
*/
protected int temperature;
public WeatherEvent(int temperature) {
this.temperature = temperature;
}
public int getTemperature() {
return temperature;
}
}
定义天气事件事件Event接口,并且增加temperature字段,用来记录当前的温度
下雨事件
/**
* 下雨事件
*
* @author silly
*/
public class RainEvent extends WeatherEvent {
public RainEvent(int temperature) {
super(temperature);
}
}
调用父类方法,传入温度
出太阳事件
/**
* 出太阳事件
* @author silly
*/
public class SunEvent extends WeatherEvent {
public SunEvent(int temperature)