Archive

Archive for the ‘Refactorings’ Category

Refactorings – Move Type to File

January 19th, 2011 Comments off

The Move Type To File refactoring allows users to move a given class, structure, interface, enumeration or delegate to a separate file. It is available when there are two or more types in the current source file.

Refactoring moves a type with a name that differs from the file name to a new source file. All comments, attributes, and XML doc comments relating to the type are moved with the type. The file will be located in the same folder as the current file and automatically added to the project. The name of the new file is based on the type’s name on which refactoring is applied.

Read more…

Refactorings – Rename

December 25th, 2010 Comments off

This refactoring provides an easy way to rename identifiers for code symbols such as locals, type members, types or namespaces and updating all their references.

Rename is one of the most useful refactorings of all. The developer can alter the name of the declaration and its occurrences (references) in the code in the whole solution.

Simply put the caret on the identifier and apply the refactoring. The refactoring will wrap all references and name of the declaration into linked identifiers, that help you easily change all occurrences simultaneously. The preview hint in Rename will show visible references in the code editor. Press Enter when you are done changing the name of the identifier to commit your changes.

Read more…

Refactorings – Extract Interface

October 25th, 2010 Comments off

Extract Interface is a refactoring that provides an easy way to create a new interface with members that originate from an existing class or struct.

When several clients use the same subset of members from a class or struct, or when multiple classes or structs have a subset of members in common, it can be useful to embody the subset of members in an interface. The Extract Interface will help to create the new interface for you. Just place the caret on the type name and perform a refactoring.

Read more…

Refactorings – Introduce Parameter Object

August 13th, 2010 Comments off

The Introduce Parameter Object refactoring consolidates selected parameters into single object. If you frequently need to pass similar sets of values to methods that tend to be passed together, it might be useful to encapsulate these values into an object that carries all of this data. It is worthwhile to turn these parameters into objects just to group the data together. As the result, calling statements will become more compact and you will be able to add data processing logic to the newly declared object. This refactoring is also useful because it reduces the size of the parameter lists, and long parameter lists are hard to read and understand.

Read more…

Refactorings – Remove Parameter

August 13th, 2010 Comments off

Also known as Remove Unused Parameter. This refactoring removes an unused parameter from a method declaration, and updates all calls accordingly. It is very useful when a parameter is no longer used by the method body. A spurious parameter doesn’t cause any problems, and you probably might need it again later. But most of the time this is the wrong choice, because a parameter indicates information that is needed. In this case, a caller has to worry about what values to pass for a fictitious, unused parameter. By not removing the parameter you are making further work for everyone who uses the method.

Read more…

Refactorings – Add Parameter

August 13th, 2010 Comments off

The refactoring adds a new parameter to a method declaration and updates all calls accordingly. This refactoring is useful when you need to quickly add a new parameter to an existing method because it needs more information from its caller that wasn’t passed in before. Bear in mind that if there are alternatives available against doing this refactoring, it is preferred to use those alternatives instead, because they don’t lead to increasing the length of parameters lists. Long parameter lists are hard to remember and often involve data clumps.

Read more…

Refactorings – Extract Method

August 13th, 2010 Comments off

The Extract Method refactoring creates a new method from the selected code block. The selection is replaced with appropriate calling code to invoke the newly-declared method. The Extract Method is great when you need to turn a big, complex method into smaller, simpler ones. Small methods are much easier to maintain, and encourage code reuse, and also have the following advantages:

  • It increases the chance that other methods can use a simple method when the method is finely organized and well-formed.
  • It allows the higher-level methods to read more like a series of comments, which improves the code readability. Simple methods with good names comment themselves, and improve overall code clarity. Overriding also is easier when the methods are finely grained.

Read more…