Create a comprehensive Design Patterns & Coding Best Practices quiz for senior developers. ## Target Audience Senior developers. Language-agnostic quiz testing design patterns and coding principles.
Single Responsibility Principle (SRP): one reason to change. Open/Closed Principle (OCP): open for extension, closed for modification. Liskov Substitution Principle (LSP): subtypes must be substitutable. Interface Segregation Principle (ISP): many specific interfaces over one general. Dependency Inversion Principle (DIP): depend on abstractions, not concretions. Examples and violations of each principle. How principles work together.
35 questionsDRY (Don't Repeat Yourself): when to apply, when not to over-apply. KISS (Keep It Simple, Stupid): avoiding unnecessary complexity. YAGNI (You Aren't Gonna Need It): avoiding speculative development. Balancing these principles. Common misconceptions.
34 questionsWhy favor composition over inheritance. Problems with deep inheritance hierarchies. Fragile base class problem. Composition: delegating to other objects. When inheritance IS appropriate. Mixins and traits concepts. Examples and trade-offs.
36 questionsWhat is Inversion of Control (IoC). Dependency Injection vs Service Locator. Constructor injection, setter injection, interface injection. IoC containers (conceptual). Service lifetimes (transient, scoped, singleton concepts). Benefits and potential over-engineering. Testing with DI.
34 questionsMeaningful naming. Functions should do one thing. Function length and arguments. Comments: when helpful vs when code should explain itself. Formatting and readability. Error handling without cluttering. Code organization and modules. The Boy Scout Rule (leave code better than found).
35 questionsWhat is Singleton pattern. Implementation approaches. Thread safety concerns. When Singleton is appropriate. Singleton anti-pattern concerns. Testing with Singletons. Alternatives to Singleton (dependency injection). Enum singleton (in languages that support it).
30 questionsFactory Method: creating objects without specifying exact class. Simple factory vs Factory Method. Abstract Factory: families of related objects. When to use each pattern. Factory Method vs Abstract Factory comparison. Parameterized factories. Factory returning factories.
30 questionsProblem: complex object construction with many parameters. Builder pattern structure. Fluent builder interface. Builder vs telescoping constructor. Immutable objects with builder. Builder pattern with validation. Builder vs Factory Method.
30 questionsWhat is Prototype pattern. Cloning objects. Shallow copy vs deep copy. When to use Prototype. Prototype registry. Prototype vs creating new objects. Language-specific clone support.
30 questionsProblem: incompatible interfaces. Object adapter vs class adapter. Adapter structure and participants. When to use Adapter. Adapter vs Decorator vs Facade. Real-world examples. Two-way adapters.
30 questionsDefining a family of algorithms and making them interchangeable. Strategy interface and concrete strategies. Context class that uses strategies. Strategy pattern vs state pattern comparison. Eliminating conditional statements with Strategy. When to use Strategy pattern. Examples: payment processing, sorting algorithms, route planning.
24 questionsEncapsulating a request as an object. Command interface with execute() method. Concrete commands and invokers. Command pattern for undo/redo operations. Macro commands and command queuing. Command vs Strategy comparison. When to use Command pattern. Examples: menu actions, transaction processing, task scheduling.
24 questionsObserver pattern structure, event-driven systems, push vs pull models, weak references, and event handling best practices.
24 questionsDecorator pattern: adding responsibilities dynamically, wrapping objects, composing decorators, versus inheritance and Aspect-Oriented Programming.
24 questionsFacade pattern: simplified interface to a subsystem, reducing complexity and coupling for clients.
24 questionsTemplate Method pattern: defining a skeleton algorithm in a base class with steps overridden by subclasses. Hollywood Principle, hooks, and comparison with Strategy.
24 questions