Rename method

Rename method

Rename Method is a refactoring that changes a name of a method into a new one, that better reveals its purpose.

To have clearer, more understandable code, programmers would optimally want to change method names to reflect exactly what the method does. For example:

public int foo(int x){ return x+1; }

would be better renamed as:

public int addOneTo(int x){ return x+1; }

The function operates the same, but is now more easily readable for developers looking through the code. Martin Fowler lists this as one of his refactorings at [http://www.refactoring.com refactoring.com] .

Take care

Although it seems to be very easy to change a method name, you can break code, if you don't keep the old method calling the new one. Don't delete the badly named old method, before all callers are changed.

If you have provided an API including the old method, you cannot delete it anyway. In this case you use actually the "Copy Method" refactoring".

:"Java 5.0 provides the annotation @Override to protect against mistakes like this."

External links

* [http://www.refactoring.com/catalog/renameMethod.html Rename Method page at refactoring.com]
* [http://www.refactoring.com/catalog/index.html Refactoring Catalog]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Code refactoring — Refactor redirects here. For the use of refactor on Wikipedia, see Wikipedia:Refactoring talk pages. Code refactoring is disciplined technique for restructuring an existing body of code, altering its internal structure without changing its… …   Wikipedia

  • Рефакторинг — (англ. refactoring) или реорганизация кода   процесс изменения внутренней структуры программы, не затрагивающий её внешнего поведения и имеющий целью облегчить понимание её работы[1][2]. В основе рефакторинга лежит последовательность… …   Википедия

  • Windows PowerShell — Screenshot of a sample PowerShell session …   Wikipedia

  • Commodore DOS — Commodore DOS, aka CBM DOS, was the disk operating system used with Commodore s 8 bit computers. Unlike most other DOS systems before or since which are booted from disk into the main computer s own RAM at startup, and executed there CBM DOS was… …   Wikipedia

  • iOS version history — Contents 1 Overview 2 Versions 2.1 Unreleased versions …   Wikipedia

  • Hygienic macro — Hygienic macros are macros whose expansion is guaranteed not to cause collisions with existing symbol definitions. They are a feature of programming languages such as Scheme and Dylan. Contents 1 The hygiene problem 2 Strategies 3 Hygienic macro… …   Wikipedia

  • Wikipedia:Criteria for speedy deletion — For requests to hide the contents of edit summaries, see Wikipedia:Oversight. WP:SPEEDY redirects here. For the guideline discussing when to end deletion debates early as keep , see Wikipedia:Speedy keep. For the list of current candidates for… …   Wikipedia

  • Wikipedia:Featured article candidates — Here, we determine which articles are to be featured articles (FAs). FAs exemplify Wikipedia s very best work and satisfy the FA criteria. All editors are welcome to review nominations; please see the review FAQ. Before nominating an article,… …   Wikipedia

  • Common elements of Final Fantasy — Articleissues cleanup = May 2008 importance = April 2008 refimprove = April 2007Though each Final Fantasy story is independent, many themes and elements of gameplay recur throughout the series. Some spin off titles have cameo appearances of… …   Wikipedia

  • Street or road name — For other uses, see Street name (disambiguation). Abbey Road in London …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”