Standard of projects [closed]

-1

An analyst told me that I need to create classes that calculate contract installments, but I realized that this calculation always takes the same steps, but depending on the type of contract, some steps are done in different ways. The steps that I could identify are: CalcValorPrincipal , CalcTaxaAdministrativa and CalcValorSeguro, after executing them the algorithm sums everything up and returns the total value of the contract. I would like to know what the recommended design pattern is to solve this problem and why is it recommended? I've been searching and it seemed like a template mode, but I'd like some help from those who "handle" more of this area.

I would like a UML diagram of this problem using the recommended pattern so that it can get a little clearer for me.

    
asked by anonymous 10.05.2016 / 03:08

1 answer

2

I do not understand much about UML, but I would use the Strategy standard that, as the name says, looks for a unique strategy for each type of situation, in the case of Contracts. Interfaces are generated that keep everything "tied".

An interface that basically only forces the implementer to calculate something.

public interface Calculavel {
    public Double calcula();
}

Implementation examples:

public class CalculoSeguroTipoX implements Calculavel{
    @Override
    public Double calcula() {
        //Aqui está a forma de calculo...
        return null;
    }
}
public class CalculoTaxaAdministrativaTipoB implements Calculavel{
    @Override
    public Double calcula() {
        //Aqui está a forma de calculo...
        return null;
    }
}
public class CalculoValorPrincipalTipoY implements Calculavel {
    @Override
    public Double calcula() {
        //Aqui está a forma de calculo...
        return null;
    }
}

We also have the Contract interface that requires every contract to have several types of implementations that are calculable.

public interface Contrato {
    public Calculavel getCalcTaxaAdministrativa();
    public Calculavel getCalcValorPrincipal();
    public Calculavel getCalcValorSeguro();
}

And finally an implementation of a contract:

public class ContratoPessoaFisica implements Contrato{

    @Override
    public Calculavel getCalcTaxaAdministrativa() {
        return new CalculoTaxaAdministrativaTipoB();
    }

    @Override
    public Calculavel getCalcValorPrincipal() {
        return new CalculoValorPrincipalTipoY();
    }

    @Override
    public Calculavel getCalcValorSeguro() {
        return new CalculoSeguroTipoX();
    }
}

I hope I have helped.

    
10.05.2016 / 06:30