โ CS Visual Lab ยท Design Patterns
๐ Decorator
๐ก The ideaAdd behaviour to an object by wrapping it in another object with the same interface. Wrappers can be stacked, instead of making many subclasses.
๐ In real lifeA plain coffee, then add milk, then add sugar: each addition wraps the cup and adds to the price.
๐ฌ Watch it work
Step 1 of 4
Base component
A simple data source.
interface Source { write(data: string): void }
class FileSource implements Source { write(d) { /* save */ } }