Ask a question from expert

Ask now

Refactored Class Diagram for University System with Inheritance and Polymorphism

29 Pages2910 Words327 Views
   

Added on  2019-09-22

About This Document

This is the refactored class diagram for the university system with proper data and method abstraction, information hiding, inheritance, and polymorphism. The base class is Person, and the derived classes are Student, Faculty, OfficeStaff, and TechnicalSupportStaff. Each class has its own attributes and methods, and they inherit the common attributes and methods from the Person class.

Refactored Class Diagram for University System with Inheritance and Polymorphism

   Added on 2019-09-22

BookmarkShareRelated Documents
a)The class diagram for the current implementation of the university systemSchoolStudent String schoolNameArrayList <Student> studentsArrayList <Faculty> facultyArrayList <OfficeStaff> o_staff ArrayList <TechnicalSupportStaff> ts_staffString firstName;String lastName;String major;double gpa;String academicLevel;School(String name)addstudent(Student s)addfaculty(Faculty f)addofficeStaff(OfficeStaff os)addTSS(TechnicalSupportStaff tss)displaySchoolInfo()Student(String fName,String lName, String al,String m, double gp)viewStudent()
Refactored Class Diagram for University System with Inheritance and Polymorphism_1
FacultyString firstNameString lastNameString departmentString researchAreadouble monthly_salaryboolean hourlyPaiddouble hourlyRateOfficeStaffString firstName;String lastName;boolean hourlyPaid;double hourlyRate;double monthly_salary;OfficeStaff(String fName,String lName, boolean hp,double ms, double hr)viewOfficeStaff()Faculty(String fName, String lName, Stringdep, String res, boolean hp, double ms,double hr)viewFaculty()TechnicalSupportStaffString firstName;String lastName;String technicalArea;boolean hourlyPaid;double hourlyRate;double monthly_salary;TechnicalSupportStaff(String fName, StringlName, String ta, boolean hp, double ms,double hr)viewTechnicalSupportStaff()
Refactored Class Diagram for University System with Inheritance and Polymorphism_2
b) Current implementation violates some of the OO design issues discussed in the class. What are the drawbacks of the design given? How can you refactor it? Here are some of the factors you need to consider Proper data and method abstraction Information hiding Using inheritance and polymorphism as needed Removing duplicate code Other “smelly code” symptoms discussed in the class as appropriateAns : The drawbacks of the given design are:There is no proper formatting of the codeIt violates the DRY (don't repeat yourself)means don't write duplicate code, instead use Abstraction and inheritance to abstract common things in one place.The benefit of this Object oriented design principle is in maintenance. It's important not to abuse it, duplication is not for code, but for functionality.We can remove unused imports Like we can remove import java.util.*; from university.javaThere are no getter and setter for the private fields in every class.
Refactored Class Diagram for University System with Inheritance and Polymorphism_3
We can refactor it byProper data and method abstraction Information hiding proper formatting of the codeUsing inheritance and polymorphism as needed Removing duplicate codeWe can also write a base class Person.javapackage university;public class Person { protected String firstName; protected String lastName; protected boolean hourlyPaid; protected double hourlyRate; protected double monthly_salary; public String getFirstName() {
Refactored Class Diagram for University System with Inheritance and Polymorphism_4
return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public boolean isHourlyPaid() { return hourlyPaid; } public void setHourlyPaid(boolean hourlyPaid) { this.hourlyPaid = hourlyPaid; }
Refactored Class Diagram for University System with Inheritance and Polymorphism_5
public double getHourlyRate() { return hourlyRate; } public void setHourlyRate(double hourlyRate) { this.hourlyRate = hourlyRate; } public double getMonthly_salary() { return monthly_salary; } public void setMonthly_salary(double monthly_salary) { this.monthly_salary = monthly_salary; }}
Refactored Class Diagram for University System with Inheritance and Polymorphism_6

End of preview

Want to access all the pages? Upload your documents or become a member.