Description
6.3 Consider the Employee class hierarchy from the beginning of Chapter 6. Use the Template Method design pattern to implement a Template Method for the Employee class: String toJson() {} that generates a JSON string with the employee’s name, base salary (the salary field), and the total salary (as returned by getSalary()).
Example:
Employee sarah = new Employee(“Sarah”);
sarah.setSalary(50000);
Manager sandy = new Manager(“Sandy”);
sandy.setSalary(100000);
sandy.setBonus(1234);
System.out.println(sarah.toJson()); // prints {“class”:”Employee”, “name”:”Sarah”, “salary”: 50000}
System.out.println(sandy.toJson()); // prints {“class”: “Manager”, “name”: “Sandy”, “salary”: 101234, “bonus”:1234}
a) Describe the mappings (table) from the pattern context to the Employee problem domain.
b) Show the UML class diagram. The diagram needs to describe the relationship between the base class Employee and subclass Manager. Include attributes and methods involved in implementing the method toJson().
c) Write the Java code for classes Employee and Manager. Include a main() method in class Manager where you illustrate how toJson() is used for objects of both classes.
Tangela Arnwine –
Great Work In Timely Fashion. Something what I wanted.
Ty Miyahara –
Great quality solution, Done way before time
Brian Duke –
Follows the required notes. Right on time. Amazing solution.
Narayana Rao –
Tutor is patient, highly efficient and well spoken. I can always count on early delivery! Thx!!