← All CAD Flashcard Decks

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
  1. When should a developer choose 'Inline Class' refactoring?

    Answer: When a class is no longer doing enough to justify its existence

    Inline Class is used when a class has become too small and its responsibilities can be absorbed into another class without losing clarity.

  2. In Test-Driven Development, what is the correct order of the TDD cycle?

    Answer: Write test → Write code → Refactor

    TDD follows Red-Green-Refactor: write a failing test, write minimal code to pass it, then refactor for quality.

  3. Which refactoring addresses the 'Long Method' code smell by finding a self-contained block of code with a clear purpose?

    Answer: Extract Method

    Extract Method pulls out a cohesive block of code into its own named method, directly addressing the Long Method smell.

  4. What does 'cohesion' mean in the context of software quality?

    Answer: The degree to which elements within a module belong together and serve a single purpose

    Cohesion measures how strongly the responsibilities of a class or module are related — high cohesion means the class has a single, focused purpose.

  5. A class uses switch statements based on the type of an object in multiple places. Which refactoring pattern resolves this?

    Answer: Replace Conditional with Polymorphism

    Replace Conditional with Polymorphism moves each branch of a type-based switch into an overridden method in a subclass, leveraging OOP dispatch.

  6. What is the primary benefit of keeping methods and classes small during refactoring?

    Answer: Improves readability, testability, and makes code easier to change safely

    Small, focused methods and classes are easier to read, reason about, test in isolation, and modify without unintended side effects.

  7. What agile practice directly prevents the buildup of technical debt by requiring all new code to meet quality standards before merging?

    Answer: Definition of Done (DoD)

    The Definition of Done includes code quality criteria (tests, reviews, refactoring) that must be met before any work item is considered complete.