Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Single Responsibility Principle */
- // Before
- class Employee {
- private final String firstName;
- private final String lastName;
- public Employee(String firstName, String lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- }
- public String getFirstName() {
- return firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public BigDecimal calculatePay() {
- // Take taxes, bonuses, overtime etc. on board
- return new BigDecimal("");
- }
- }
- // After
- class Employee {
- private final String firstName;
- private final String lastName;
- public Employee(String firstName, String lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- }
- public String getFirstName() {
- return firstName;
- }
- public String getLastName() {
- return lastName;
- }
- }
- class PayCalculator {
- public BigDecimal calculatePay(Employee employee) {
- // Calculate pay and take taxes, bonuses, overtime etc. on board
- return new BigDecimal("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment