When do we need decorator pattern?

后端 未结 9 961
攒了一身酷
攒了一身酷 2020-12-02 18:32

When is it necessary to use the decorator pattern? If possible, give me a real world example that is well-suited for the pattern.

9条回答
  •  生来不讨喜
    2020-12-02 19:21

    If you are familiar with Swing development in Java (along with other GUI toolkits), you'll see the decorator pattern used a lot. You might have a constructor that takes in a specific component and then adds functionality to it.

    Here is a good article that uses Swing as an example.

提交回复
热议问题