I have to create a program using strategy pattern to implement SOLID principle. The program goes , the user logged in via email / DBLogger (Database logger) / text file and if the calculated tax is negative or incorrect the program throws exception. The exception method occurs via mimicing Textfile or DBLogger or email. Then how to throw it please show. I am unable to write it .
What makes you think handlin exceptions is any different if you use different patterns?
Don't start interface names with I.
Don't start method names with CapitalLetters.
Don't use the new Date() constructor. Don't use the java.util.Date class at all. Use the new date-time API.
posted 1 year ago
@Campbell Ritchie . I want to know the syntax of how to include the syntax in here if the value of rate 'r' goes 0 or negative. Since i implemented strategy pattern for the if else statement, now how to include it here in Tax Calculator class
posted 1 year ago
here for this code i have to include calculate class in new Tax Calculator.
Your if-else-if statement in the exception block nullifies the use of the Strategy pattern, the point of which is to avoid such a construct. Go back and review what the context and motivation is for Strategy.
I don't understand what you mean by "how to include the exception" -- try to describe what you're trying to do in a different way because that phrase doesn't make sense to me.
You have a method called calculateTax() that could throw a RuntimeException if the years parameter value is zero. You have various ways to log an exception, all of which implement the ILogger interface. If you're trying to adhere to SOLID principles, which part of SOLID in particular do you think is being violated by your code right now? How does using Strategy help you stick to SOLID then?