Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
StatefulCalculator.java
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
You can’t perform that action at this time.