 Okay so our final structural pattern is the decorator pattern and as the name suggests the idea is that you take something that exists and decorate it you put things on top of it and imagine for example you have a function and algorithm that writes something to to a file it takes some input text or binary and writes it to a file and a common decorator would be to on top of that add functionality that buffers it so that you don't get any issues during writing for example so that's a common thing or maybe you want to add functionality that first encrypts it and then writes it to the disk and that's the the case for the decorator pattern what happens is that we have an interface a component that does something for example our algorithm and we could have a concrete component that realizes this for example this is our writing algorithm it just writes something to the disk then we get into the decorator we have a class that also realizes the component interface that's our base decorator so again it has an execute method but the big difference to a regular component is that it also has a reference to components so basically a base decorator has a number of components it can keep track of them and that way we can actually attach it to existing things and then if you subclass this with a concrete decorator you can add extra functionality so basically you override the execute method but you add something to it and then the the way this would look like is that you would probably call your extra functionality so for example our buffering or our encryption and then you would call the original execute method and in many programming languages that's for example done with the super dot execute method so basically you still keep the original functionality you still call it but you additionally call something else you add something on top so basically you can build these stacks you can decorate existing things and this algorithm example is a typical case you might want to think add things on top of file system operations or database operations another case where you have this commonly is in graphical editors so text editors IDEs graphics programs any kind of thing where you want to have components in your IDE buttons editors text fields menus whatever but you want to make them extensible so if you for example consider eclipse in the eclipse IDE you can extend pretty much everything you can add things on top of that and this is this might appear similar to you in to the observer pattern the difference here the observer pattern was all about representation when something changes we inform something else here it's kind of attaching something to it adding extra functionality on top without having to change the original thing so if you want to have an algorithm that is encryption you don't have to take the original one copy it and rewrite it you just add something on top or if you want to implement a new editor in the clips that deals with your kind of files that you have just made up you just decorate the existing editor without having to rewrite everything so that's the the idea of the decorator pattern of course there again a number of solid principles here at play it's the open closed we're not modifying any of this we're just extending it it's the single responsibility each decorator has a specific use case we're not trying to expand inflate our original component we're not just adding extra things we're actually having specific responsibilities here so this is what the decorator pattern is and now next up we go into the creation of patterns so the patterns that deal with how do we create instances of a class