Created
April 29, 2013 11:44
-
-
Save rondinif/5481109 to your computer and use it in GitHub Desktop.
StatefulCalculator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.rondadev.samples; | |
/** | |
* @author rondadev | |
* | |
*/ | |
public class StatefulCalculator { | |
private StatelessCalculator calculator; | |
double register = 0; | |
public double add(double a) { | |
register = calculator.add(register, a); | |
return register; | |
} | |
public double subtract(double a) { | |
register = calculator.subtract(register, a); | |
return register; | |
} | |
public double multiply(double a) { | |
register = calculator.multiply(register, a); | |
return register; | |
} | |
public double divide(double a) { | |
register = calculator.divide(register, a); | |
return register; | |
} | |
public double display() { | |
return register; | |
} | |
public void clean() { | |
register = 0; | |
} | |
public void turnOff() { | |
calculator = null; | |
System.out.println("[StatefulCalculator] Good bye ! "); | |
} | |
public void turnOn() { | |
calculator = new StatelessCalculator(); | |
System.out.println("[StatefulCalculator] Welcome !"); | |
} | |
@SuppressWarnings("unused") | |
private void afterCreated() { | |
System.out.println("[StatefulCalculator] PostConstruct callback !"); | |
} | |
@SuppressWarnings("unused") | |
private void beforeRemoved() { | |
System.out.println("[StatefulCalculator] PreDestroy callback !"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment