Pattern Design Architectural and Enterprise Patterns 2 — Questions and Answers
Question 1: Dependency Injection (DI) is an implementation of which design principle?
- Dependency Inversion Principle (Correct answer)
- Open/Closed Principle
- Single Responsibility Principle
- Liskov Substitution Principle
Correct answer: Dependency Inversion Principle
DI implements the Dependency Inversion Principle by making high-level modules depend on abstractions, with concrete dependencies provided externally.
Question 2: The Unit of Work pattern tracks:
- All changes to objects during a business transaction and writes them in one batch (Correct answer)
- Individual service calls to external APIs
- The sequence of commands for undo/redo
- Partitioned read and write database connections
Correct answer: All changes to objects during a business transaction and writes them in one batch
Unit of Work maintains a list of objects affected by a business transaction and coordinates writing out all changes in a single batch.
Question 3: The Strangler Fig pattern is used in software architecture to:
- Incrementally replace a legacy system by routing traffic to new code (Correct answer)
- Isolate monolithic services behind an API gateway
- Decompose a database into event streams
- Decouple read and write models in a distributed system
Correct answer: Incrementally replace a legacy system by routing traffic to new code
The Strangler Fig pattern gradually replaces a legacy system by building new functionality alongside it and routing requests to new code piece by piece.
Question 4: In the Hexagonal (Ports and Adapters) architecture, 'ports' are:
- Interfaces that define how the application communicates with the outside world (Correct answer)
- HTTP endpoints for REST APIs
- Database connection pools
- Message queue topics
Correct answer: Interfaces that define how the application communicates with the outside world
Ports are technology-neutral interfaces that define the application's boundary, while Adapters implement those interfaces for specific technologies.
Question 5: Which pattern ensures that different bounded contexts in a microservice system can communicate without direct coupling?
- Anti-Corruption Layer (Correct answer)
- Strangler Fig
- Repository
- Service Locator
Correct answer: Anti-Corruption Layer
An Anti-Corruption Layer translates between the models of two bounded contexts, preventing one context's model from polluting another.
Question 6: The Outbox Pattern in microservices ensures:
- Reliable message publishing by writing events to the same database transaction as the state change (Correct answer)
- Commands are queued before being executed
- Events are deduplicated before consumption
- Service discovery is handled automatically
Correct answer: Reliable message publishing by writing events to the same database transaction as the state change
The Outbox Pattern writes messages to an outbox table in the same transaction as the domain change, ensuring events are never lost even if the message broker is temporarily unavailable.
Dependency Injection (DI) is an implementation of which design principle?