Refactoring an redundant if-Statement

Viewed 180

So I am currently doing Refactoring of some classes. I found one class, which has two methods. In the first method it has following if-Statement:

if(sapData.getTime > 100 || sapData.getUserName != null && sapData.getBusinessValue > 0)

(keep in mind i kind of easied it up a bit.)

And in the second method I have:

if(data.getTime > 100 || data.getNameOfUser != null && data.getBValue > 0)

As you can see, the logic behind the if-statements is exactly the same. But sapData and data are different objects and the Methods (which are really only getters) have different names.

What I want to do now, is to write a method isValid in which I can pass either a SapData Object or a Data Object.

Inheritance isn't an option, because they should be seperated.

5 Answers
Related