DSA Factory
Free Design patterns lessonsDesign patterns · Stage 1 · Structuring objects · Step 2

Decorator

Adding behaviour to an object by wrapping it in another with the same interface, instead of subclassing for every combination. About 12 minutes.

Quick check

What is the difference in intent between decorator and proxy, which are structurally similar?

  1. AA decorator adds behaviour; a proxy controls access to the object
  2. BA decorator changes the interface; a proxy keeps it
  3. CThere is no difference
Show the answer

A decorator adds behaviour; a proxy controls access to the object. Same shape, different purpose.

Lock it in

4 questions on this idea

Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.

Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve