 Let's take a look at the decorator design pattern. This one is a little bit different than what we've been talking about. So the intent here is to attach additional responsibilities to an object dynamically. Now you can think of this like wrapping a gift. You're going to put it into a box, then you're going to wrap the box. So really you're kind of just putting objects and objects and objects, but each object does something slightly different. It's part of an overall process. Let's take a look at an example of the decorator here. So what we're going to do is HTML tags. If you don't know HTML, don't worry. We're not going to deep dive into HTML. I'm just going to show you how to do some basic text processing here. So first things first here, we're going to add a new and I'm starting from scratch. I'm going to say we want a text class. This, of course, is going to be a Q object. Once we get in here, I can say we want to include QDbug and I'm going to say virtual void process. So the whole point of this function here is just simply going to be to process some type of string. That's all we're going to do. Let's go ahead and add this. Now in here, I'm going to say if parents. Notice how the first thing I'm doing is saying we have to have some type of parent. Then I'm going to say text Q object cast going to cast that parent, whatever it is to, you guessed it, this class. And if we're able to cast that, then I'm going to say text process. And then we're just going to process this input. And this may look a little weird. You may be going, wait a minute, why are you doing it this way? Well, what we're going to do is we're going to make another class. And I'm going to say, let's call this, I need like a special name, bold text. Why not? I struggle with coming up with names sometimes. And inside of bold text, we are just going to inherit the class we just made text. Grab this, make sure that we actually add that in there. If we don't like that, we could just grab it like this. Bunch of different ways you can do this. Then we're going to switch and in here, this is where the magic really happens. I'm going to say text. So we're going to take our base class, we're going to process that input. And then I'm going to say input and I'm going to insert at zero to starting position. And this is where if you don't know HTML, you may be a little bit confused. But this is the HTML tag for bolding something or we're going to start to bold. Then I'm going to say input append at the very end. I'm going to turn off the HTML tag. That's kind of how HTML works. You turn a tag on, you turn it off. So in HTML, anything after this is bold and anything before this is bold. So the text in between. So notice the order here. I'm saying bold text process. And then we're going to call text process our base class, which does effectually nothing. But once we actually chain these together, which we're about to do, you'll see exactly what I'm talking about here. So I'm going to make another class. It's called this italic text. And we're going to just go bang. And what is the problem here? Direct base Q object inaccessible due to ambiguity. Maybe it's because I have one too many of those. There we go. That should fix it. Slightly embarrassing that I missed that first time around. But mistakes will be made. Let's go ahead. Not make the same mistake again. And we're going to go ahead and we are going to just insert virtual function of base class. Going to add that in bang. If we don't like it here, we can get rid of all this formatting and put it right up here. And then we can grab our bold text, flip over to italic, and then we can just set the HTML decorator there. So if you're kind of following along here, what we're doing is bold will take the text and just encapsulate it in the HTML bold. Italic will take the text and encapsulate it inside of the HTML italic. Seems kind of weird. Why would we do something like that? Well, if we flip into our main, and I'm just going to put some includes in here, we're going to have text, bold text, italic text, and let's just play around with this. And let's look at the decorator design pattern in action. So I'm going to say Q string. And let's call this value equal text. Now I'm going to say text, t, and then we're going to chain some things together. And I'm going to say new, bold text, and then new, italic text. Now you may be going, no, wait a minute, whoa, whoa, whoa. You just created a memory leak. You're absolutely right. We did. Realistically, memory leaks aren't that dangerous in this context because as soon as this application quits, my operating system is going to go in and free up as much memory as it can. That is not a guarantee. So we want to make sure we do actually free up that memory some way, somehow. So really all we're doing here is we're chaining these together. We have a text, which is going to hit bold and then italic. Now we're going to process that. Let's go ahead and say Q and phone. And I want to take that value back. So what do you think is going to happen here? Save and run. And let's look and see. There is our outputted text. Bold, bold, italic, italic. So if you guessed it's wrapping it, you're absolutely right. So really all we're doing is we are using the decorator pattern. This is extremely flexible. You're going to see this in many variants out in the wild. And to be brutally honest, a lot of applications you use, use this pattern whether they realize it or not.