Skip to content

Commit

Permalink
add Introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
wangweiqing committed Jul 31, 2014
1 parent 309d216 commit bbc3d87
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.wwq.calculator;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;

@Aspect
public class CalculatorIntroduction {
@DeclareParents(
value = "com.wwq.calculator.ArithmeticCalculatorImpl",
defaultImpl = MaxCalculatorImpl.class)
public MaxCalculator maxCalculator;

@DeclareParents(
value = "com.wwq.calculator.ArithmeticCalculatorImpl",
defaultImpl = MinCalculatorImpl.class)
public MinCalculator minCalculator;
}
7 changes: 6 additions & 1 deletion src/main/resources/java/com/wwq/calculator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ public static void main(String[] args) {
ArithmeticCalculator arithmeticCalculator = (ArithmeticCalculator) context
.getBean("arithmeticCalculator");
/* arithmeticCalculator.add(1, 2);*/
arithmeticCalculator.sub(4, 3);
/* arithmeticCalculator.sub(4, 3);*/
/* arithmeticCalculator.mul(2, 3);
arithmeticCalculator.div(4, -1);*/
MaxCalculator maxCalculator = (MaxCalculator) arithmeticCalculator;
maxCalculator.max(1, 2);
MinCalculator minCalculator = (MinCalculator) arithmeticCalculator;
minCalculator.min(1, 2);


/* UnitCalculator unitCalculator = (UnitCalculator) context
.getBean("unitCalculator");
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/java/com/wwq/calculator/MaxCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wwq.calculator;

public interface MaxCalculator {
public double max(double a, double b);
}
20 changes: 20 additions & 0 deletions src/main/resources/java/com/wwq/calculator/MaxCalculatorImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wwq.calculator;

import org.apache.log4j.Logger;

public class MaxCalculatorImpl implements MaxCalculator {
/**
* Logger for this class
*/
private static final Logger logger = Logger
.getLogger(MaxCalculatorImpl.class);

@Override
public double max(double a, double b) {
// TODO Auto-generated method stub
double result = (a >= b) ? a : b;
logger.info("max(" + a + ", " + b + ") = " + result);
return result;
}

}
5 changes: 5 additions & 0 deletions src/main/resources/java/com/wwq/calculator/MinCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wwq.calculator;

public interface MinCalculator {
public double min(double a, double b);
}
20 changes: 20 additions & 0 deletions src/main/resources/java/com/wwq/calculator/MinCalculatorImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wwq.calculator;

import org.apache.log4j.Logger;

public class MinCalculatorImpl implements MinCalculator {
/**
* Logger for this class
*/
private static final Logger logger = Logger
.getLogger(MinCalculatorImpl.class);

@Override
public double min(double a, double b) {
// TODO Auto-generated method stub
double result = (a <= b) ? a : b;
logger.info("min(" + a + ", " + b + ") = " + result);
return result;
}

}
1 change: 1 addition & 0 deletions src/main/webapp/WEB-INF/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class="com.wwq.calculator.UnitCalculatorImpl" />
<bean class="com.wwq.calculator.CalculatorLoggingAspect" />
<bean class="com.wwq.calculator.CalculatorValidationAspect"/>
<bean class="com.wwq.calculator.CalculatorIntroduction"/>



Expand Down

0 comments on commit bbc3d87

Please sign in to comment.