Code Refactoring and Quality Flashcards
7 cards from real CAD practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Code Refactoring and Quality flashcards as text
Which refactoring technique removes duplication by pulling common behavior into a shared base class?
Answer: Pull Up Method
Pull Up Method moves identical or similar methods from subclasses into their parent class to eliminate duplication.
What is the primary purpose of the 'Replace Temp with Query' refactoring?
Answer: Eliminate a temporary variable by replacing it with a method call
Replace Temp with Query extracts the expression assigned to a temp variable into its own method, making the code more readable and reusable.
In the context of code quality metrics, what does 'cognitive complexity' measure?
Answer: How difficult code is to understand due to control flow nesting and branching
Cognitive complexity measures how hard code is for a human to understand, penalizing nested control structures and non-linear flow.
Which design smell describes a class that knows too much about another class's internal structure?
Answer: Inappropriate Intimacy
Inappropriate Intimacy occurs when a class accesses too many internal details of another class, violating encapsulation.
When applying the 'Decompose Conditional' refactoring, what happens to complex if-else logic?
Answer: The condition and branches are extracted into separate named methods
Decompose Conditional extracts the condition expression and each branch into well-named methods to clarify intent.
What is the 'Strangler Fig' pattern used for in the context of refactoring?
Answer: Gradually replacing a legacy system by routing new functionality through a new system
The Strangler Fig pattern incrementally migrates a legacy system by routing traffic to new code while keeping the old system alive until it can be retired.
Which metric measures the number of linearly independent paths through a method's source code?
Answer: Cyclomatic Complexity
Cyclomatic complexity counts independent execution paths through a method, and is a key indicator of testability and maintainability.