Lecture thumbnail 0:00 / 0:00 If you go ahead and you look at the interface for a Stringbuilder, you’ll find something interesting.

You’ll take a look at the append function, for example.

You can see that the function itself, the method in fact returns a stringbuilder.

And this is done so that on the stringbuilder you can chain methods together.

So you can say SB dot append foo and then put a dot at the end and append bar.

Now we’re going to do the same thing for our builder.

It’s actually quite easy because all you have to do is you have to go into the actual builder.

And whenever we do add child, for example, we can return a reference to our original object.

So here I can return an HTML builder and I can say return this.

And that’s really it.

Now what I can do is I can chain both of these calls so I can get rid of the builder reference here

and I can just tag it at the end of Add Child.

So this is a very well known approach in object oriented design, which is called a fluent interface,

an interface which allows you to chain several calls by returning a reference to the object you’re working

with.

In this case, that’s our builder.

Play Play Play Play Stop Play Play Play Play Start Play