Question 71
HardWhich pattern separates an abstraction from its implementation so that both can vary, such as shapes and drawing APIs?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
Which pattern separates an abstraction from its implementation so that both can vary, such as shapes and drawing APIs?
Adapter
Proxy
Bridge
Mediator
Sign up free to see the answer and a step-by-step explanation.
Which pattern encapsulates a request as an object, enabling undo, queuing and logging?
Observer
State
Iterator
Command
Sign up free to see the answer and a step-by-step explanation.
Which pattern changes an object's behaviour when its internal state changes, replacing large if-else blocks on a state field?
Visitor
State
Strategy
Template Method
Sign up free to see the answer and a step-by-step explanation.
What is the main difference between the Strategy and State patterns?
State is a creational pattern
Strategy changes the object's class
In Strategy the client chooses the algorithm; in State the object switches its own behaviour as its state changes
They are identical
Sign up free to see the answer and a step-by-step explanation.
Which principle does a 'God class' with thousands of lines and dozens of responsibilities most obviously violate?
Single Responsibility
Interface Segregation
Law of Demeter
Liskov Substitution
Sign up free to see the answer and a step-by-step explanation.
What does high coupling between modules cause?
A change in one module forces changes in many others
Better testability
Fewer bugs
Faster compilation
Sign up free to see the answer and a step-by-step explanation.
What is dependency injection's relationship to the Dependency Inversion Principle?
They are unrelated
DI is a technique for supplying the abstractions that DIP says modules should depend on
DIP is a framework
DI forbids interfaces
Sign up free to see the answer and a step-by-step explanation.
A team adds a configuration system for 20 options when the product currently needs 2. Which principle warns against this?
LSP
YAGNI
DRY
SOLID
Sign up free to see the answer and a step-by-step explanation.
Two modules contain the same tax calculation, and a bug fix is applied to only one. Which principle would have prevented this?
ISP
YAGNI
KISS
DRY
Sign up free to see the answer and a step-by-step explanation.
Which pattern is used by event listeners and GUI frameworks to notify many subscribers of a change?
Observer
Singleton
Adapter
Factory
Sign up free to see the answer and a step-by-step explanation.