CS FundamentalsHardGATE CS · TCS NQT Prime · Product Company SDE
A logging library needs to let client code add new, optional behaviours (timestamping, compression, encryption) to a basic file writer, in any combination, without creating an explosive number of subclasses for every combination. Which pattern fits?
- A. Factory Method pattern
- B. Singleton pattern
- C. Adapter pattern
- D. Decorator pattern
Correct answer: D. Decorator pattern
Decorator wraps an object with additional objects implementing the same interface, letting behaviours be composed and combined at run time instead of needing a subclass for every combination.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- What risk does a 'merge queue' (serialising merges to main, re-testing each change against the latest main before it actually lands)…
- A module of 50000 lines of code has 30 defects found in testing. What is the defect density, in defects per KLOC?
- Which of these is a core difference between Scrum and Kanban as commonly practised?
- A module of 15000 lines of code has 41 defects found in testing. What is the defect density, in defects per KLOC?
- A function contains 9 binary decision points (if/while/for conditions), and no other branching. Using V(G) = (number of decision points) +…
- What does git rebase do differently from git merge when integrating a feature branch onto main?