OCP | The Open Closed Principle
class Calculator {
public float add(float a, float b) {
return a + b
}
public float subtract(float a, float b) {
return a — b
}
}Calculator calculator = new Calculator()
float sum = calculator.add(10, 2) //the value of sum is 12
float diff = calculator.subtract(10, 2) //the value of diff is 8public float multiply(float a, float b) {
return a * b
}最后更新于