Re: Can this Class be cleaned up at all?
John T wrote:
package employees;
....
public class Employee {
....
private float initialSalary;
....
float is probably the very worst type to represent money.
public Employee(int employeeNumber, String employeeName, Calendar
date, float initialSalary, String jobTitle) {
...
}
public Employee( int employeeNumber, String employeeName,
Calendar date, float initialSalary ) {
this( employeeNumber, employeeName, date, initialSalary, null );
}
void displayAll () {
System.out.println( "Employee Information" );
.... consider passing a PrintWriter as an argument rather than hardcoding
System.out.
}
void displayHireDate()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Make this a static final DateFormat.
System.out.println("Hire Date: " + sdf.format(this.hireDate));
Same comment about out.
}
....
}
Is there anything that can be changed to make it look less clunky?
What makes you call it clunky?
I was thinking about making it an interface and having it implemented but
when I thought about the IS-A HAS-A guideline I thought it would make
more sense to have the Employee class and an interface called
EmployeeDoes to encapsulate the methods.
Instead of starting out thinking about classes and interfaces, start thinking
about employees and what they do in the world that you are modeling.
Modeling is about nouns and verbs. "Employee" is a noun. Not every verb makes
sense with "employee". Do you want to model employees quacking? Having salaries?
Nouns are the actors in a process: employee, department, manager, salary.
Verbs are the actions they can perform: departments can add or remove
employees, employees can receive increased or reduced salaries.
- Lew