which design choose? - pros and cons

Posted by Guarava Makanili on Stack Overflow See other posts from Stack Overflow or by Guarava Makanili
Published on 2010-06-09T17:48:16Z Indexed on 2010/06/09 17:52 UTC
Read the original article Hit count: 161

Filed under:
|
|

Which of these 3 approches would choose and why?

// This is the one I would choose

class Car {

}

class FeeCalculator {

    public double calculateFee(Car car) {
        return 0;
    } 
}

// in that case the problem might be when we use ORM framework and we try to invoke save with parameter Car

class Car {

    private FeeCalculator calculator;

    public double calculateFee() {
        return calculator.calculateFee(this); 
    }
}

class FeeCalculator {

    public double calculateFee(Car car) {
        return 0;
    }
}

// in that case the problem mentioned above is solved, but I don't like this design

class Car {

    public double calculateFee(FeeCalculator calculator) {
        return calculator.calculateFee(this); 
    }
}

class FeeCalculator {

    public double calculateFee(Car car) {
        return 0;
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about design