Created
September 14, 2015 14:42
-
-
Save rymawby/e89092d5da58427979ca to your computer and use it in GitHub Desktop.
Improve this with "Tell, don't ask".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSalary() : Number | |
var employee:Employee = new Employee() | |
var salary:Number = employee.salary | |
if(employee.hasBonus) { | |
salary = employee.salary * 1.1 | |
} | |
return salary | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kinda feel as though this function would never exist as is. You would, surely, have the getSalary function as a method of the Employee class?
But..
Class Employee
var salary:Number
var bonus:Number
var hasBonus:Boolean
function getSalary() : Number {
if (hasBonus) {
return salary * bonus
}
return salary
}
End
thus you can then do:
var Ryan:Employee = new Employee()
Ryan.getSalary()
returning the value of the salary without having to break the encapsulation of the employee state - if setBonus has been called then you will get a salary with a bonus, else you wont.