Re: Can this Class be cleaned up at all?
- From: John T <printdude1968@xxxxxxxxx>
- Date: Sun, 25 Feb 2007 03:23:15 GMT
Patricia Shanahan wrote:
John T wrote:Interesting. All I need to do is change the way that the initialSalary is defined in the Employee class and the other classes that extend it should be easy to retrofit. Or will they? What if I have 8 classes that extend Employee and I change the way initialSalary is defined? That means that every class that extends employee and creates a new employee will have to have the call to the constructor changed. Is there a cool way around that? I also have a Manager class that extends Employee. When I create a new Manager I would have to change the way that initialSalary is passed to the construtor. This seems to me to be a bit much.
private float initialSalary;
float is almost always the wrong type. It only has the equivalent of 24
significant bits, less than 8 significant digits. That means the cents
figure of a high annual salary might be in danger.
Either BigDecimal, or an integer count of cents (or other minimalSo you are saying that if I want to create a new employee with a salary of 40,000$ I would have the initialSalary instance variable defined as BigDecimal initialSalary;
currency unit), works well. If you really need floating point operations
on your salaries, use double.
So if I wanted to display it via a displayAll method in the class, I would need to divide it by 100 for it to make sense. Something like:
public void displayAll()
{
......
System.out.println("Salary: " + this.initialSalary / 100);
}
public Employee(int employeeNumber, String employeeName, Calendar date, float initialSalary) {
this.employeeNumber = employeeNumber;
this.employeeName = employeeName;
this.initialSalary = initialSalary;
this.hireDate = date.getTime();
}
You could use:
this(employeeNumber, employeeName, date, initialSalary, 0);
instead of the method body. That makes it easier to see that it is doing
the same thing as the six argument constructor, but with the salary left
zero.
I did not know you could do that. Thank you. I am not sure that I understand it though. My constructor only has 4 instance variables. Where are you getting six from? Am I missing something?
From my consideration of what I am going to use, the EmployeeDoes interface will allow for different types of employees (i.e. managers and directors) to implement methods like takeAVacation differently. If a normal employee wants to take a vacation he/she has to
Would doing that gain any flexibility that you think you would find
useful in your program?
Patricia
a) fill out a form
b) book the time
c) get approval
whereas the spec I am working from says that a Director only needs to book the time and it's done. This means to me, that the implementation of a takeAVacation method is different for a director than for a regular employee. Hence, the need for an interface. Make sense?
.
- References:
- Can this Class be cleaned up at all?
- From: John T
- Re: Can this Class be cleaned up at all?
- From: Patricia Shanahan
- Can this Class be cleaned up at all?
- Prev by Date: Re: Can this Class be cleaned up at all?
- Next by Date: Re: Can this Class be cleaned up at all?
- Previous by thread: Re: Can this Class be cleaned up at all?
- Next by thread: Re: Can this Class be cleaned up at all?
- Index(es):
Relevant Pages
|
|