CPSA Designing Building Blocks Questions and Answers — Questions and Answers
Question 1: When designing the building block view of a software system, which of the following is the primary goal of striving for high cohesion within individual building blocks?
- To ensure that a building block is responsible for a single, well-defined purpose. (Correct answer)
- To minimize the dependencies a building block has on other building blocks.
- To allow multiple, unrelated functionalities to be managed in a single component.
- To increase the number of operations a building block's public interface exposes.
Correct answer: To ensure that a building block is responsible for a single, well-defined purpose.
High cohesion is a software design principle that states that all elements within a module or building block should be strongly related and focused on a single, well-defined task. This enhances readability, maintainability, and reusability.
Question 2: An architect is designing a new e-commerce system. They have created a 'PaymentProcessing' building block. To improve maintainability and testability, this block should not directly access the 'CustomerDatabase'. Which design principle should the architect apply to decouple these two building blocks?
- Single Responsibility Principle
- Open/Closed Principle
- Liskov Substitution Principle
- Dependency Inversion Principle (Correct answer)
Correct answer: Dependency Inversion Principle
The Dependency Inversion Principle suggests that high-level modules (like 'PaymentProcessing') should not depend on low-level modules (like 'CustomerDatabase'). Both should depend on abstractions (e.g., an interface like 'ICustomerRepository'). This inverts the typical dependency, decoupling the components and making the system more modular and testable.
Question 3: You are documenting a building block for other teams to use. What information is essential to include in the black-box description?
- The internal algorithms and private helper methods used.
- The specific database schema tables it directly manipulates.
- Its public interfaces, responsibilities, and required quality attributes. (Correct answer)
- The hierarchical decomposition into smaller, internal building blocks.
Correct answer: Its public interfaces, responsibilities, and required quality attributes.
A black-box description defines a building block from an external perspective, focusing on what it does, not how it does it. This includes its public interfaces (the 'how to use it'), its responsibilities (the 'what it does'), and any quality attributes (e.g., performance guarantees) that consumers can expect. Internal implementation details are part of the white-box view.
Question 4: A team is building a reusable 'Logging' component. To ensure it can be used across many different projects with varying requirements, which practice is most critical?
- Tightly coupling the component to the company's main application framework.
- Hard-coding configuration values like file paths and log levels for consistency.
- Using configurable parameters and avoiding hard-coded values. (Correct answer)
- Designing the component to handle only a single, specific logging format.
Correct answer: Using configurable parameters and avoiding hard-coded values.
To maximize reusability, a building block should be flexible and adaptable. Using configurable parameters instead of hard-coding values allows the component to be customized for different environments and use cases without changing its internal code.
Question 5: Which of the following scenarios best describes tight coupling between two building blocks?
- Building block A sends an asynchronous message to a queue that building block B reads from.
- Building block A calls an interface that building block B implements.
- Building block A directly modifies a data structure that is internal to building block B. (Correct answer)
- Building block A and B are deployed in separate microservices.
Correct answer: Building block A directly modifies a data structure that is internal to building block B.
Tight coupling occurs when one component has intimate knowledge of the internal workings of another. Directly modifying another block's internal data structure is a classic example of high coupling, creating a fragile system where a change in block B can easily break block A.
Question 6: An architect is reviewing a system design and finds a single building block that manages user authentication, generates PDF reports, and sends email notifications. Which design principle is most clearly being violated?
- Don't Repeat Yourself (DRY)
- Single Responsibility Principle (SRP) (Correct answer)
- Interface Segregation Principle (ISP)
- Dependency Inversion Principle (DIP)
Correct answer: Single Responsibility Principle (SRP)
The Single Responsibility Principle (SRP) states that a module or building block should have only one reason to change, meaning it should have only one primary responsibility. This block has three distinct responsibilities (authentication, reporting, notifications), thus violating SRP.
When designing the building block view of a software system, which of the following is the primary goal of striving for high cohesion within individual building blocks?