Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Behavioral Design Patterns

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

__________ is a behavioral design pattern that lets an object alter its behavior when its internal state changes. It appears as if the object changed its class.

a)

State

b)

Command

c)

Mediator

d)

Observer

2.

What concept is the State pattern closely related to?

a)

Finite Machine

b)

State Machine

c)

Finite-Stable Machine

d)

Finite-State Machine

3.

The main idea of the State Pattern is that, at any given moment, there’s a ________ number of states which a program can be in.

a)

infinit

b)

finit

c)

finalized

d)

finished

4.

What kind of operators are mostly implemented in the State machine?

a)

conditional

b)

loop

c)

assignment

d)

all of the mentioned

5.

What pattern can we use when having an object that behaves differently depending on its current state, the number of states is enormous, and the state-specific code changes frequently?

a)

Command

b)

Mediator

c)

State

d)

Observer

6.

Use this pattern when you have a class polluted with massive conditionals that alter how the class behaves according to the current values of the class’s fields. What pattern?

a)

Observer

b)

Mediator

c)

State

d)

Strategy

7.

What pattern you can use when having a lot of duplicate code across similar states and transitions of a condition-based state machine.

a)

Observer

b)

Mediator

c)

State

d)

Command

8.

Implementation of State Pattern organizes the code related to particular states into separate classes and introduces new states without changing existing state classes or the context. Which of SOLID principles would follow you?

a)

Single Responsibility

b)

Open/Closed

c)

Interface Segregation

d)

Dependency Inversion

9.

__________ is a behavioral design pattern that lets you define a family of algorithms and put each of them into a separate class, and make their objects interchangeable.

a)

Strategy

b)

State

c)

Observer

d)

Memento

10.

Use the ______________ pattern when you want to use different variants of an algorithm within an object and be able to switch from one algorithm to another during runtime.

a)

State

b)

Mediator

c)

Strategy

d)

Template Method

11.

Notice up prostitutes of Strategy Pattern

a)

You can swap algorithms used inside an object at runtime.

b)

You can not replace inheritance with composition

c)

You can isolate the implementation details of an algorithm from the code that uses it.

d)

You can replace inheritance with composition.

12.

_______________ is a behavioral design pattern that defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.

a)

Visitor

b)

Template Method

c)

State

d)

Strategy

13.

The ____________ lets you turn a monolithic algorithm into a series of individual steps which can be easily extended by subclasses while keeping intact the structure defined in a superclass.

a)

Abstract Method

b)

Template Method

c)

Factory Method

d)

Chain of Responsibility

14.

______________ is a behavioral design pattern that lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.).

a)

Mediator

b)

Memento

c)

Iterator

d)

Observer

15.

Use the Iterator pattern when your collection has a complex data structure under the hood, but you want to hide its complexity from clients (either for convenience or security reasons).

a)

True

b)

False

16.

Using an iterator may be more efficient than going through elements of some specialized collections directly.

a)

True

b)

False

17.

_____________ is a behavioral design pattern that lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object.

a)

Memento

b)

Mediator

c)

Observer

d)

State

18.

Use the Mediator pattern when you can’t reuse a component in a different program because it’s too dependent on other components.

a)

True

b)

False

19.

_____________ is a behavioral design pattern that lets you save and restore the previous state of an object without revealing the details of its implementation.

a)

Mediator

b)

Memento

c)

State

d)

Strategy

20.

In which pattern you can produce snapshots of the object’s state without violating its encapsulation?

a)

Mediator

b)

Memento

c)

State

d)

Visitor