lundi 27 avril 2015

Design feedback

Can you please give me a feedback about this design implementation ?

Suppose i need to calculate a salary of an Employer, this salary is depending on something called : REGIME, the REGIME is either newRegime or OldRegime.

Suppose the calculation should be as following :

If (newRegime) then Salary = 10; If (oldRegime) then Salary = 30 if 30 is superior then newRegime.

I tought about this implementation :

An interface : SalaryBusiness

    public interface SalaryBusiness {

    double getSalary();
}

A Class SalaryCalculator :

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;
}

}

// Child classes : NewRegimeCalculator / OldRegimeCalculator

    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;
}
    }

// The Client using the design

public classWantToGetTheSalary {

Object anObject;
double salary;
   SalaryCalculator regimeCalculator = new SalaryCalculator().getRegimeCalculator(anObject);

//Here is our salary 
salary = regimeCalculator.getSalary();


}

I am sorry if this is hard to read, i would so greatful if you can give me some feedback, whats the prons & cons of this implementation ? is it worth to get on production ? is it a just crap code ? does it respect the SOLID Principles ?.... Thank you in advance :)

Aucun commentaire:

Enregistrer un commentaire