vendredi 29 juillet 2016

Tasks design pattern with conditions

All the snippet code will be in java while my code will be implemented in scala, so maybe some solution could get use of the advantages of that language.

I'm trying to perform some post-conditions over some data I get after executing some code and would like to know the best pattern to use.

Let's see that when executing the command I can pass by parameter (this is java) certain information.

-DallTheSame=true -DconcreteExpectedResultPerUnit=3,1,1 -DminimumThreshold=60

Then I started to look into the best approach to solve the problem of how to be able to extend that in some future.

1. Visitor Pattern

All of the parameter will have an associated class

class AllTheSameCheck
class ConcreteExpectedResultPerUnitCheck
class MinimumThresholdCheck

all will implement the visit and then the time to execute the checks come, the same object will visit all of them and if required, will execute the check

class AllTheSameCheck {
    public void visit(Object object) {
        if(isAllTheSameDefined()){
            // do the check
        }
    }
}

and the same code for the others.

2. Decorator Pattern

Same as before in terms of classes

class BasicCheck
class AllTheSameDecoratorCheck extends BasicCheck
class ConcreteExpectedResultPerUnitDecoratorCheck extends BasicCheck
class MinimumThresholdDecoratorCheck extends BasicCheck

but it will not be a decorator as per see, because in the main execution code they will need to be defined with conditionals

Main Code:

BasicCheck basicCheck = new BasicCheck()
if(isAllTheSameDefined()){
    basicCheck = new AllTheSameDefined(basicCheck)
}
if(isConcreteExpected...Defined()){
    basicCheck = new ConcreteExpected....(basicCheck)
}

So, having into account that all the post-conditions are defined when executing the tests, which is the best design pattern in that case?

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire