Logo
Pattern

Discover published sets by community

Explore tens of thousands of sets crafted by our community.

Code Refactoring Techniques

10

Flashcards

0/10

Still learning
StarStarStarStar

Rename Method

StarStarStarStar

Definition: Changing the name of a method to better convey what the method does. When to Use: Use when the method name is not descriptive of its purpose or has become misleading due to code changes over time.

StarStarStarStar

Introduce Explaining Variable

StarStarStarStar

Definition: Involves adding a named variable that explains the purpose of the complex expression. When to Use: Use when you have a complicated expression that is hard to understand at a glance.

StarStarStarStar

Extract Class

StarStarStarStar

Definition: Create a new class to hold data or methods that do not fit the current class's main responsibility. When to Use: Use when a class is doing too much work and has more than one responsibility.

StarStarStarStar

Inline Method

StarStarStarStar

Definition: Inline Method is the process of replacing a method call with the actual method body. When to Use: Use when the method is not complex and does not add clarity to the code.

StarStarStarStar

Encapsulate Field

StarStarStarStar

Definition: Transforming public fields into private fields with public getter and setter methods to provide access. When to Use: Use when you need to impose validation logic or encapsulation on fields accessed from outside the class.

StarStarStarStar

Extract Method

StarStarStarStar

Definition: This technique involves creating a new method by extracting a section of code from an existing method. When to Use: Use when you have code that can be grouped together, when a method is too long, or when code chunks are duplicated.

StarStarStarStar

Extract Interface

StarStarStarStar

Definition: Creating a new interface with methods that are common across different classes. When to Use: Use when multiple classes have a common set of methods, which can be used to define a common interface.

StarStarStarStar

Replace Temp with Query

StarStarStarStar

Definition: Instead of storing a result in a temporary variable, use a method to return the result directly. When to Use: Use when a temporary variable is used only to hold the result of an expression and is not modified later.

StarStarStarStar

Move Method

StarStarStarStar

Definition: This technique involves moving a method from its current class to another class where it is more relevant. When to Use: Use when a method is more concerned with the data or behavior of another class.

StarStarStarStar

Collapse Hierarchy

StarStarStarStar

Definition: The process of simplifying an inheritance hierarchy by either merging a subclass into a superclass or vice versa. When to Use: Use when a subclass and superclass are not different enough to warrant a separate hierarchy.

Know
0
Still learning
Click to flip
Know
0
Logo

© Hypatia.Tech. 2024 All rights reserved.