1/21
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is the Decorator pattern?
A pattern that attaches additional responsibilities to an object dynamically.
What is the definition of Decorator?
Attach additional responsibilities to an object dynamically; decorators provide a flexible alternative to subclassing for extending functionality.
What problem does Decorator solve?
It adds new functionality without modifying the original class and without needing a huge number of subclasses.
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.
What principle is mentioned as a reason not to modify InputStreamReader?
The Open/Closed Principle.
When should Decorator be used?
When you want to add responsibilities dynamically, possibly remove them later, and subclassing is impractical.
What is the key exam phrase for Decorator?
Dynamic extension without subclass explosion.
What are the main roles in Decorator?
Component, ConcreteComponent, Decorator, and ConcreteDecorator.
What does the Decorator class usually contain?
A reference to a Component object that it wraps.
How does a decorator typically work?
It forwards operations to the wrapped component and adds extra behavior before or after.
In the Java example, what is the Component type?
Reader.
What are some concrete component classes shown in the slides?
CharArrayReader, InputStreamReader, StringReader, and FileReader.
What decorator class is shown in the reader diagram?
BufferedReader.
What extra behavior does BufferedReader add in the slides?
readLine().
What class extends the decorated reader behavior with line numbering?
LineNumberReader.
Why is FileInputStream -> BufferedInputStream -> GZIPInputStream a Decorator example?
Because each object wraps the previous one and adds new behavior.
What is one benefit of Decorator?
It provides more flexibility than static inheritance.
What is another benefit of Decorator?
It can add or remove responsibilities at runtime.
What is another benefit of Decorator?
It avoids feature-laden classes high in the hierarchy.
What is one downside of Decorator?
It adds complexity and creates lots of little objects.
What is an important identity warning with Decorator?
A decorator and its component are not identical objects.
What is a good memory trick for Decorator?
It is like wrapping an object in layers to add features.