Skip to content

Design Patterns: Decorator

Kaisinel edited this page Feb 13, 2021 · 7 revisions

Decorator

Problem

Have you ever had a need to stack behaviour to an existing implementation? For example, imagine there are 3 behaviours: A, B, C with the same definitions. You need to do a mix of them: either A or B or C or AB or AC or BC or ABC. In fact, the order itself matters too. Inheritance could be one of the solutions, but there is another, better way.