Structural patterns
Decorator
Adds behaviour by wrapping an object instead of multiplying subclasses.
Article
Decorator – adding behaviour layer by layer
Decorator wraps an object in another object with the same interface and adds behaviour before or after the call. An example of caching, retries and logging for an exchange rate provider in C#, TypeScript, Java, Go and Python.
Related articles
- Proxy – a stand-in that controls access to the real object
Proxy has the same interface as the real object and stands in front of it, deciding when – and whether – to pass a call on. An invoice archive example with access control and a lazy connection in…
- Composite – trees in which a leaf and a branch look the same
Composite lets you treat a single object and a whole group of objects in exactly the same way. A course curriculum example with modules and lessons in C#, TypeScript, Java, Go and Python.
- Adapter – how to get along with code that speaks another language
Adapter translates the interface of a foreign class into the interface your code expects. An example of integrating a third-party geocoding SDK in C#, TypeScript, Java, Go and Python.
Challenges
- Debounce and throttle medium
- Design patterns – basics Quiz
Around the topic
- Decorator Pattern – Design Patterns (ep 3) video · youtube · Christopher Okhravi
- Decorator article · web · Refactoring.Guru
- Building Your Own CQRS Pipeline With Decorators (Dropped MediatR!) video · youtube · Milan Jovanović
- Head First design patterns book · openlibrary · Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates
- Dekorator / Decorator article · web · Refactoring.Guru
- Episode 9. It’s the Holidays! Let’s Decorate! podcast · apple-podcasts · Java Pub House