File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Roadmap/27 - SOLID OCP/java Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,46 @@ public static void main(String[] args) {
77 //libraryViolationOcp();
88 libraryFollowOCP ();
99 }
10+ /*************************** Ejercicio adicional con ocp(Correcto) ***************************/
11+ interface Operation {
12+ double function (double num1 , double num2 );
13+ }
14+
15+ static class Addition implements Operation {
16+ @ Override
17+ public double function (double num1 , double num2 ) {
18+ return num1 + num2 ;
19+ }
20+ }
21+
22+ static class Subtraction implements Operation {
23+ @ Override
24+ public double function (double num1 , double num2 ) {
25+ return num1 - num2 ;
26+ }
27+ }
28+
29+ static class Multiplication implements Operation {
30+ @ Override
31+ public double function (double num1 , double num2 ) {
32+ return num1 * num2 ;
33+ }
34+ }
35+
36+ static class Division implements Operation {
37+ @ Override
38+ public double function (double num1 , double num2 ) {
39+ return num1 / num2 ;
40+ }
41+ }
42+
43+ static class CalculatorOCP {
44+ public double Calculate (Operation operation , double num1 , double num2 ){
45+ return operation .function (num1 , num2 );
46+ }
47+ }
48+
49+
1050 /*************************** Ejercicio adicional sin ocp(Incorrecto) ***************************/
1151 static class Calculator {
1252 public double calculate (String operation , double num1 , double num2 ){
You can’t perform that action at this time.
0 commit comments