CPSA Software Design Principles 5 — Questions and Answers
Question 1: Which design principle is MOST directly related to the concept of an 'anti-corruption layer' in domain-driven design?
- Single Responsibility Principle
- Separation of Concerns (Correct answer)
- YAGNI
- Liskov Substitution Principle
Correct answer: Separation of Concerns
An anti-corruption layer separates different domain models or contexts, directly embodying Separation of Concerns by isolating external system concerns from internal domain logic.
Question 2: When evaluating software design, 'afferent coupling' (Ca) measures:
- The number of packages that a package depends on
- The number of packages that depend on a given package (Correct answer)
- The ratio of abstract classes to total classes
- The cyclomatic complexity of a module
Correct answer: The number of packages that depend on a given package
Afferent coupling (Ca) counts the number of external packages that depend on a given package, indicating how responsible that package is to others.
Question 3: A module has high efferent coupling (Ce). What risk does this MOST indicate?
- Other modules are heavily dependent on this module
- This module is unstable because changes in dependencies can force changes here (Correct answer)
- The module violates the Single Responsibility Principle
- The module has insufficient abstraction
Correct answer: This module is unstable because changes in dependencies can force changes here
High efferent coupling means a module depends on many others; if any of those dependencies change, this module may also need to change, making it unstable.
Question 4: Which metric is computed as I = Ce / (Ca + Ce) and indicates the instability of a software package?
- Abstractness (A)
- Instability (I) (Correct answer)
- Distance from the Main Sequence (D)
- Cyclomatic Complexity (CC)
Correct answer: Instability (I)
Robert Martin's Instability metric I = Ce / (Ca + Ce) ranges from 0 (maximally stable) to 1 (maximally unstable), measuring a package's resilience to change.
Question 5: What does the 'Stable Dependencies Principle' prescribe about the direction of dependency between packages?
- Packages should only depend on packages that are more abstract
- Packages should depend in the direction of stability (Correct answer)
- Circular dependencies are acceptable if packages are cohesive
- Dependencies should be minimized regardless of stability
Correct answer: Packages should depend in the direction of stability
The Stable Dependencies Principle states that a package should only depend on packages that are more stable than itself, ensuring stable packages are not forced to change due to unstable dependents.
Question 6: Which design approach BEST supports achieving 'testability' as a quality attribute in a system?
- Maximizing the use of global variables for shared state
- Designing with clear interfaces and injected dependencies (Correct answer)
- Combining all business logic into a single large class
- Hard-coding configuration values into production classes
Correct answer: Designing with clear interfaces and injected dependencies
Clear interfaces and dependency injection allow dependencies to be replaced with test doubles (mocks/stubs), making units independently testable.
Question 7: In software architecture, 'conceptual integrity' (as described by Fred Brooks) is BEST achieved by:
- Having as many developers as possible contribute design ideas independently
- Ensuring a unified, consistent design vision guides the entire system (Correct answer)
- Using the most advanced technology available for each component
- Maximizing feature richness to satisfy all stakeholder needs
Correct answer: Ensuring a unified, consistent design vision guides the entire system
Brooks argued that conceptual integrity — a single, coherent design vision — is the most important factor in system design quality, best achieved through a consistent governing architecture.
Which design principle is MOST directly related to the concept of an 'anti-corruption layer' in domain-driven design?