From the course: Java Design Patterns: Structural

Unlock the full course today

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

Solution: The Bridge pattern

Solution: The Bridge pattern - Java Tutorial

From the course: Java Design Patterns: Structural

Start my 1-month free trial

Solution: The Bridge pattern

(upbeat music) - [Instructor] Let's take a look at my solution to the exercise. If yours looks a bit different to mine, that's fine. So I now have an interface called ButtonSize, which has one method called getSize. Next, I have three classes that implement ButtonSize called LargeButtonSize, MediumButtonSize and SmallButtonSize. They each override the getSize method and print out the size of the button. Now each of my different types of button, DropdownButton, CheckboxButton, and RadioButton, are rule concrete classes, which have a field of type button size. And in the constructor of each of them, I'm passing in a button-size object. Finally, in the Canvas class, for each button I'm creating, I'm passing in a new button-size object, which specifies the size of button I want to have, instead of having a separate class for each size and type of button. So I now have two separate hierarchies, one for the button type,…

Contents