📄 sensoradapter.aj
字号:
package designpatterns.adapter.aspectj;import designpatterns.adapter.model.*;public aspect SensorAdapter { declare parents : (TemperatureGauge || RadiationDetector) implements StatusSensor; public String TemperatureGauge.getStatus(){ if(this.readTemperature() > 160){ return "DANGER"; } return "OK"; } public String RadiationDetector.getStatus(){ if(this.getCurrentRadiationLevel() > 1.5){ return "DANGER"; } return "OK"; } //restricts the use of StatusSensor to a given package// declare error :// call(* StatusSensor.*(..)) && !within(designpatterns.adapter.aspectj..*)// : "The StatusSensor interface is restricted."; //prevents the use of Sensor methods directly, all access must go through //StatusSensor// declare error :// call(* StatusSensor+.*(..)) // && !call(* StatusSensor.*(..))// && within(AspectJReadout) :// "The readout class can only interact with Sensors through StatusSensor";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -