From the course: Java Design Patterns: Behavioral Part 1

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Solution: The Interpreter pattern

Solution: The Interpreter pattern - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 1

Start my 1-month free trial

Solution: The Interpreter pattern

(upbeat music) - Now let's have a look at my solution to this exercise. As usual, yours might look a bit different and that's totally fine. So I've got an interface called Expression, which defines a single method called interpret. This takes a String as an argument and returns a String. Then I have three concrete implementations of this. The first is EndsWithPeriod. I'm using the HelperMethods to handle the logic. So I'm doing context = HelperMethods and calling the EndsWithPeriod method. And then I'm returning the context. Next I've got one called NoRepeatedWords, which again uses the HelperMethod and then cause the interpret method on EndsWithPeriod. And finally, I have FirstLetterIsUpperCase. Again, this cause the HelperMethod and then cause the interpret method on NoRepeatedWords and the Main class. I'm creating a variable of type FirstLetterIsUpperCase as this is the last thing I'm checking and I'm calling the…

Contents