CPA Software Development & Design Principles 2 — Questions and Answers
Question 1: Which SOLID principle states that a class should have only one reason to change?
- Open/Closed Principle
- Single Responsibility Principle (Correct answer)
- Liskov Substitution Principle
- Interface Segregation Principle
Correct answer: Single Responsibility Principle
The Single Responsibility Principle (SRP) states that a class should have only one responsibility and therefore only one reason to change.
Question 2: In the context of design patterns, which pattern provides a simplified interface to a complex subsystem?
- Adapter
- Decorator
- Facade (Correct answer)
- Proxy
Correct answer: Facade
The Facade pattern defines a simplified interface that makes a complex subsystem easier to use.
Question 3: What does the term 'cohesion' refer to in software design?
- The degree to which modules depend on each other
- The degree to which elements within a module belong together (Correct answer)
- The number of classes in a package
- The depth of inheritance in a class hierarchy
Correct answer: The degree to which elements within a module belong together
Cohesion measures how closely related and focused the responsibilities of a single module or class are.
Question 4: Which Agile ceremony is used to inspect the increment and adapt the Product Backlog?
- Sprint Planning
- Daily Scrum
- Sprint Review (Correct answer)
- Sprint Retrospective
Correct answer: Sprint Review
The Sprint Review is held at the end of a Sprint to inspect the increment and adapt the Product Backlog if needed.
Question 5: What is the primary purpose of refactoring code?
- Adding new features to existing code
- Fixing bugs in production
- Improving code structure without changing external behavior (Correct answer)
- Optimizing database queries
Correct answer: Improving code structure without changing external behavior
Refactoring improves the internal structure of code while preserving its observable behavior.
Question 6: Which design pattern separates the construction of a complex object from its representation?
- Factory Method
- Abstract Factory
- Builder (Correct answer)
- Prototype
Correct answer: Builder
The Builder pattern separates the construction of a complex object from its representation, allowing different representations to be created.
Question 7: In Test-Driven Development (TDD), what is the correct order of steps?
- Write code, write test, refactor
- Write test, write code, refactor (Correct answer)
- Refactor, write test, write code
- Write test, refactor, write code
Correct answer: Write test, write code, refactor
TDD follows the Red-Green-Refactor cycle: write a failing test first, write code to pass it, then refactor.
Which SOLID principle states that a class should have only one reason to change?