From the course: Design Patterns: Creational

Unlock the full course today

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

Solution: A builder design

Solution: A builder design

From the course: Design Patterns: Creational

Start my 1-month free trial

Solution: A builder design

(upbeat electronic music) - [Instructor] Here's the challenge solution. We have an abstract builder, at the top right, that specifies the append and insert methods. Our concrete string builder extends this class and allows us to append and insert partial strings to create a completed string. Of course, other builders that build aggregate structures using append and insert, can extend this class too. The director on the left is composed with the builder it will use to build strings. The director has a construct method with the code we'll use to build a string with the string builder. In the construct method, we insert and add strings to the builder and once we're ready, we call the two-string method to build and return the completed string.

Contents