200 likes | 210 Views
Explore applying aspect-oriented programming ideas in a component-based context using composition adapters. Learn possible approaches, examples, and conclusions for effective integration.
E N D
Applying aspect-oriented programming ideas in a component based context: Composition Adapters. Wim Vanderperren System and Software Engineering Lab (SSEL) Vrije Universiteit Brussel (VUB) Pleinlaan 2, 1050 Brussels, Belgium 姓名:陳源順 學號:E9406002 指導老師:張顧耀老師
Outline AOP (Aspect – oriented programming) Component Based Possible Approaches Example of composition adapters Conclusions
Aspect – oriented programming package java.io; public class File implements java.io.Serializable { private String path; ... public boolean exists() { // JAAS security service call SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkRead(path); } return exists0(); }
Aspect – oriented programming public boolean canRead() { // JAAS security service call SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkRead(path); } return canRead0(); } … // repeat for 16 times Crosscutting concern
Aspectual component Composition adapters consist of two part Context Describes the behavior that will be adapted. Adapter Describes the adaptation itself.
Example of composition adapters public aspect SensorAdapter { declare parents : (TemperatureGauge || RadiationDetector) implements StatusSensor; }
Example of composition adapters public class TemperatureGauge{ public int readTemperature(){ //accesses sensor internals } }
Example of composition adapters public class RadiationDetector { public double getCurrentRadiationLevel(){ //read radiation somehow } }
Example of composition adapters Readout: Sensor 1 status is OK Sensor 2 status is OK Sensor 3 status is BORDERLINE Sensor 4 status is DANGER!
Example of composition adapters public static void main(String[] args){ RadiationDetector radiationDetector = //find critical detector TemperatureGauge gauge = //get exhaust nozzle gauge List allSensors = new ArrayList(); allSensors.add(radiationDetector); allSensors.add(gauge); int count = 1; for (Sensor sensor : allSensors) { //How to read each type of sensor...? } }
Example of composition adapters if(this.readTemperature() > 160){ return "DANGER"; } return "OK"
Example of composition adapters public aspect SensorAdapter { declare parents : (TemperatureGauge || RadiationDetector) implements StatusSensor; }
Example of composition adapters public String TemperatureGauge.getStatus() { if(this.readTemperature() > 160) { return "DANGER"; } return "OK"; }
Conclusions Easy to understand Repetition use Maintenance Combination