Refactoring in the DVT Eclipse IDE - How To Perform Extract To Method Refactoring

Description

This video from shows you how to extract a block of actions to a separate new method. This way you keep methods shorter and easier to understand. Just select a code fragment and press Ctrl+1 - a new method with adequate arguments is created, and the selection is replaced with a method call.

Explore the design and verification tools: https://www.dvteclipse.com
Or request a license: https://www.dvteclipse.com/request-license

Transcript

Introduction

You can easily move a code fragment to a separate new method. This is called Extract Method Refactoring. It helps keep methods shorter and easier to understand.

How to Perform Extract Method Refactoring

  1. Select several statements from a task or function and press CTRL+1.
  2. Use the up and down arrows to pick a proposal and then press ENTER to apply it.
  3. The selected code fragment is replaced with a method call.
  4. You can give it a meaningful name.
  5. The newly created method contains the code fragment you initially selected.

Understanding Method Arguments After Refactoring

The newly created method arguments are computed automatically. Any local variables declared prior to the code fragment you extracted become arguments of the newly created method. Each argument direction is computed accordingly:

  • Input for arguments that are only read
  • Output for arguments that are only written
  • In-out for arguments that are both read and written in the selected block of actions.