Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface SalaryBusiness {
- double getSalary();
- }
- public class SalaryCalculator implements SalaryBusiness {
- // Some shared fileds, useful for the calculation....
- // A public constructor
- public SalaryCalculator()
- {
- }
- protected SalaryCalculator(Object anObject)
- {
- // the anObject is useful to init the shared fileds
- initFields(anObject)
- }
- //Method that creat a Regime
- public final SalaryCalculator getRegimeCalculator(Object anObject)
- {
- if (newRegimeCalculator.equals(anObject.getRegime))
- {
- return new newRegimeCalculator(anObject);
- }else {
- NewRegimeCalculator newRegimeCalcultor = new NewRegimeCalculator(anObject);
- OldRegimeCalculator oldRegimeCalculator = new OldRegimeCalculator(anObject);
- oldRegimeCalculator.setTauxNr = newRegime.getSalary();
- return oldRegimeCalculator
- }
- @override
- public double getSalary()
- {
- return 0.0d;
- }
- }
- public class NewRegimeCalculator extends SalaryCalculator {
- // Special fileds...
- // Procted constructor
- proctected NewRegimeCalculator(Object anObject) {
- super(anObject);
- }
- @override
- public double getSalary()
- {
- double salary = 0.0d;
- //Traitements....
- return salary;
- }
- }
- public class OldRegimeCalculator extends SalaryCalculator {
- // Field holding the newRegime salary
- double tauxNr = 0.0d;
- // Special fileds...
- // Procted constructor
- proctected OldRegimeCalculator(Object anObject) {
- super(anObject);
- }
- @override
- public double getSalary()
- {
- double salary = 0.0d;
- //Traitements....
- if (tauxNr>salary)
- {
- return tauxNr;
- }
- else {
- return salary;
- }
- }
- public classWantToGetTheSalary {
- Object anObject;
- double salary;
- SalaryCalculator regimeCalculator = new SalaryCalculator().getRegimeCalculator(anObject);
- //Here is our salary
- salary = regimeCalculator.getSalary();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement