sensoradapter.aj
来自「designpatterns for aop」· AJ 代码 · 共 39 行
AJ
39 行
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 + =
减小字号Ctrl + -
显示快捷键?