CAD FREE CAD Code Refactoring and Quality Questions and Answers 2 — Questions and Answers
Question 1: Which refactoring technique involves replacing a complex conditional expression with a method that returns a boolean value?
- Decompose Conditional (Correct answer)
- Extract Method
- Inline Method
- Replace Temp with Query
Correct answer: Decompose Conditional
Decompose Conditional extracts the condition and each branch into separate methods, making complex conditionals easier to understand.
Question 2: What is the primary purpose of establishing a 'Definition of Done' for code quality in an Agile team?
- To create a shared understanding of quality standards that must be met before work is considered complete (Correct answer)
- To assign blame when defects are found in production
- To eliminate the need for code reviews
- To reduce the number of user stories completed per sprint
Correct answer: To create a shared understanding of quality standards that must be met before work is considered complete
A Definition of Done ensures the entire team agrees on the quality criteria every increment must satisfy before it can be released.
Question 3: In the context of Agile development, what does 'technical debt' most accurately describe?
- The implied cost of future rework caused by choosing an expedient solution over a better approach (Correct answer)
- The total cost of software licenses used by the development team
- The amount of time spent on writing documentation
- The budget allocated for infrastructure upgrades
Correct answer: The implied cost of future rework caused by choosing an expedient solution over a better approach
Technical debt represents the extra development work that arises when code that is easy to implement in the short run is used instead of applying the best overall solution.
Question 4: Which code quality metric measures the percentage of code executed during automated tests?
- Code coverage (Correct answer)
- Cyclomatic complexity
- Coupling
- Cohesion
Correct answer: Code coverage
Code coverage measures the proportion of source code that is exercised by the test suite, typically expressed as a percentage.
Question 5: What is the 'Strangler Fig' pattern used for in Agile refactoring?
- Gradually replacing a legacy system by incrementally building new functionality around it (Correct answer)
- Removing all legacy code in a single sprint
- Adding a wrapper class around every legacy module
- Duplicating the entire codebase before making changes
Correct answer: Gradually replacing a legacy system by incrementally building new functionality around it
The Strangler Fig pattern incrementally replaces parts of a legacy system with new implementations until the old system can be completely decommissioned.
Question 6: Why should refactoring be performed in small, incremental steps rather than large-scale rewrites?
- To maintain a working system at all times and reduce the risk of introducing defects (Correct answer)
- To avoid the need for version control
- To ensure only one developer works on the code at a time
- To eliminate the need for automated testing
Correct answer: To maintain a working system at all times and reduce the risk of introducing defects
Small incremental refactoring steps keep the system functional throughout the process, making it easier to identify and fix any issues that arise.
Which refactoring technique involves replacing a complex conditional expression with a method that returns a boolean value?