Skip to main content

Quiz 2.6: Questions with a name

Question 1 — The Decorator pattern

Which UML diagram belongs to the Decorator pattern?

Show correct answer

A wrapper that adds behaviour around a component

Explanation

The Decorator wraps a component and forwards calls to it, so behaviour can be added without subclassing.

Question 2 — Which pattern wraps a component?

Which pattern wraps a component?

Show correct answer

Decorator

Testing FizzBuzz

Given this class:

public class FizzBuzz {
public String fizzbuzzer(int n) {
return n % 15 == 0 ? "FizzBuzz" : String.valueOf(n);
}
}
Subquestion 1a — Which test is useful? (2 points)

Which test is useful?

Show correct answer

A test that asserts "FizzBuzz" for input 15

Subquestion 1b — What does fizzbuzzer(7) return? (1 point)

What does fizzbuzzer(7) return?

Show correct answer

7