-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
############################## | ||
# STRATEGY # | ||
# STRATEGY # | ||
############################## | ||
|
||
- We use interfaces to use polymorphism in our doing. | ||
|
||
- We broke the use of several 'ifs', with that we can invoke a method that according to its | ||
instance it can call a method implemented differently than another instance. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package strategy; | ||
|
||
public class Budget { | ||
|
||
private double value; | ||
|
||
Budget(double value) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
public double getValue() { | ||
return value; | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package strategy; | ||
|
||
public interface Tax { | ||
|
||
public double calculate(Budget budget); | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package strategy; | ||
|
||
public class TaxCalculator { | ||
|
||
public void calculate(Budget budget, Tax anyTax) { | ||
|
||
double valueResult = anyTax.calculate(budget); | ||
System.out.println("Value: " + valueResult + ". Class @Override: " + anyTax.getClass().getSimpleName()); | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package strategy; | ||
|
||
public class TaxICMS implements Tax { | ||
|
||
@Override | ||
public double calculate(Budget budget) { | ||
return budget.getValue() * 0.1; | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package strategy; | ||
|
||
public class TaxINSS implements Tax { | ||
|
||
@Override | ||
public double calculate(Budget budget) { | ||
return budget.getValue() * 0.2; | ||
} | ||
|
||
} |