lec 39: structural design patterns, part 4

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/21

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:21 PM on 4/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

22 Terms

1
New cards

What is the Decorator pattern?

A pattern that attaches additional responsibilities to an object dynamically.

2
New cards

What is the definition of Decorator?

Attach additional responsibilities to an object dynamically; decorators provide a flexible alternative to subclassing for extending functionality.

3
New cards

What problem does Decorator solve?

It adds new functionality without modifying the original class and without needing a huge number of subclasses.

4
New cards

Why is subclassing not a great solution in the reader example?

Because many different reader classes would each need their own subclasses, causing a subclass explosion.

5
New cards

What principle is mentioned as a reason not to modify InputStreamReader?

The Open/Closed Principle.

6
New cards

When should Decorator be used?

When you want to add responsibilities dynamically, possibly remove them later, and subclassing is impractical.

7
New cards

What is the key exam phrase for Decorator?

Dynamic extension without subclass explosion.

8
New cards

What are the main roles in Decorator?

Component, ConcreteComponent, Decorator, and ConcreteDecorator.

9
New cards

What does the Decorator class usually contain?

A reference to a Component object that it wraps.

10
New cards

How does a decorator typically work?

It forwards operations to the wrapped component and adds extra behavior before or after.

11
New cards

In the Java example, what is the Component type?

Reader.

12
New cards

What are some concrete component classes shown in the slides?

CharArrayReader, InputStreamReader, StringReader, and FileReader.

13
New cards

What decorator class is shown in the reader diagram?

BufferedReader.

14
New cards

What extra behavior does BufferedReader add in the slides?

readLine().

15
New cards

What class extends the decorated reader behavior with line numbering?

LineNumberReader.

16
New cards

Why is FileInputStream -> BufferedInputStream -> GZIPInputStream a Decorator example?

Because each object wraps the previous one and adds new behavior.

17
New cards

What is one benefit of Decorator?

It provides more flexibility than static inheritance.

18
New cards

What is another benefit of Decorator?

It can add or remove responsibilities at runtime.

19
New cards

What is another benefit of Decorator?

It avoids feature-laden classes high in the hierarchy.

20
New cards

What is one downside of Decorator?

It adds complexity and creates lots of little objects.

21
New cards

What is an important identity warning with Decorator?

A decorator and its component are not identical objects.

22
New cards

What is a good memory trick for Decorator?

It is like wrapping an object in layers to add features.