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
A developer notices that several classes all pass the same three parameters together in multiple method calls. Which refactoring should be applied?
Answer: Introduce Parameter Object
Introduce Parameter Object groups related parameters that always travel together into a single object, reducing parameter list length.
What does the SOLID principle 'D' (Dependency Inversion) state?
Answer: High-level modules should not depend on low-level modules; both should depend on abstractions
Dependency Inversion Principle states high-level modules and low-level modules should both depend on abstractions, not on each other directly.
Which refactoring technique is best when a method is used more often in another class than in its own class?
Answer: Move Method
Move Method relocates a method to the class that uses it most, reducing Feature Envy and improving cohesion.
In agile development, what is a 'code smell' in a production codebase?
Answer: A surface indication that usually corresponds to a deeper problem in the code
A code smell is a symptom in code that suggests a possible deeper design problem worth investigating and refactoring.
What is the goal of 'Replace Magic Number with Symbolic Constant' refactoring?
Answer: Replace unexplained literal values with named constants that express intent
This refactoring replaces hard-coded literal numbers with named constants, making code self-documenting and easier to maintain.
Which practice is most aligned with maintaining code quality in an agile team?
Answer: Integrating refactoring into every sprint alongside feature development
Agile teams treat refactoring as a continuous activity woven into every sprint, preventing technical debt from accumulating.
What does the 'Law of Demeter' (Principle of Least Knowledge) restrict?
Answer: An object's method from calling methods on objects returned by other method calls
The Law of Demeter states a method should only call methods on its direct dependencies, avoiding chained calls like a.getB().getC().doSomething().