CPSA Software Design Principles 4 — Questions and Answers
Question 1: Interface Segregation Principle (ISP) recommends that clients should NOT be forced to depend on interfaces they do not use. What is the PRIMARY design remedy?
- Merge all interfaces into one comprehensive interface
- Split large interfaces into smaller, role-specific ones (Correct answer)
- Replace interfaces with abstract classes
- Use adapter patterns to wrap the large interface
Correct answer: Split large interfaces into smaller, role-specific ones
ISP recommends splitting fat interfaces into multiple focused, role-specific interfaces so clients only depend on the methods they actually use.
Question 2: Which term describes the degree to which elements within a module belong together and relate to a single purpose?
- Coupling
- Cohesion (Correct answer)
- Encapsulation
- Abstraction
Correct answer: Cohesion
Cohesion measures how closely related and focused the responsibilities of a single module are — high cohesion means all elements serve a common purpose.
Question 3: Preferring composition over inheritance is recommended primarily because composition:
- Eliminates the need for interfaces entirely
- Avoids breaking changes when parent class internals change (Correct answer)
- Always produces faster runtime performance
- Requires less code than inheritance hierarchies
Correct answer: Avoids breaking changes when parent class internals change
Composition avoids the fragile base class problem — changes to a parent class cannot break subclasses because composed objects are accessed through interfaces, not inherited directly.
Question 4: What quality attribute is MOST directly improved by applying abstraction in software design?
- Security
- Modifiability / maintainability (Correct answer)
- Throughput
- Fault tolerance
Correct answer: Modifiability / maintainability
Abstraction hides implementation details behind stable interfaces, making it easier to change internals without affecting dependent components, directly improving modifiability.
Question 5: Which scenario is an example of 'feature envy' as a code smell related to design principles?
- A class with too many public methods
- A method that uses data and methods from another class more than its own (Correct answer)
- A subclass overriding all parent methods
- An interface with a single method
Correct answer: A method that uses data and methods from another class more than its own
Feature envy occurs when a method accesses another object's data far more than its own class's data, suggesting the method may belong in the other class.
Question 6: In the CPSA (iSAQB) framework, which concept describes the degree to which software components can be understood, changed, and tested in isolation?
- Availability
- Modifiability (Correct answer)
- Interoperability
- Scalability
Correct answer: Modifiability
Modifiability (maintainability) refers to how easily software can be understood, modified, extended, and tested, which is a primary goal of good design principles.
Question 7: Which of the following BEST illustrates a violation of the Dependency Inversion Principle?
- A high-level business logic class directly instantiates a specific database class (Correct answer)
- A class implements two different interfaces
- A method returns an interface type rather than a concrete type
- A module depends on an abstract factory
Correct answer: A high-level business logic class directly instantiates a specific database class
When a high-level module directly instantiates a concrete low-level class (e.g., a specific database), it creates a hard dependency on implementation details, violating DIP.
Interface Segregation Principle (ISP) recommends that clients should NOT be forced to depend on interfaces they do not use.
What is the PRIMARY design remedy?