20 questions
__________ 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.
State
Command
Mediator
Observer
What concept is the State pattern closely related to?
Finite Machine
State Machine
Finite-Stable Machine
Finite-State Machine
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.
infinit
finit
finalized
finished
What kind of operators are mostly implemented in the State machine?
conditional
loop
assignment
all of the mentioned
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?
Command
Mediator
State
Observer
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?
Observer
Mediator
State
Strategy
What pattern you can use when having a lot of duplicate code across similar states and transitions of a condition-based state machine.
Observer
Mediator
State
Command
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?
Single Responsibility
Open/Closed
Interface Segregation
Dependency Inversion
__________ 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.
Strategy
State
Observer
Memento
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.
State
Mediator
Strategy
Template Method
Notice up prostitutes of Strategy Pattern
You can swap algorithms used inside an object at runtime.
You can not replace inheritance with composition
You can isolate the implementation details of an algorithm from the code that uses it.
You can replace inheritance with composition.
_______________ 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.
Visitor
Template Method
State
Strategy
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.
Abstract Method
Template Method
Factory Method
Chain of Responsibility
______________ is a behavioral design pattern that lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.).
Mediator
Memento
Iterator
Observer
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).
True
False
Using an iterator may be more efficient than going through elements of some specialized collections directly.
True
False
_____________ 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.
Memento
Mediator
Observer
State
Use the Mediator pattern when you can’t reuse a component in a different program because it’s too dependent on other components.
True
False
_____________ is a behavioral design pattern that lets you save and restore the previous state of an object without revealing the details of its implementation.
Mediator
Memento
State
Strategy
In which pattern you can produce snapshots of the object’s state without violating its encapsulation?
Mediator
Memento
State
Visitor