Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed



email article
printer friendly
more resources

Refactor Your Way to Migration Success
Take advantage of the top ten refactorings for VB6-.NET migration to create easier-to-read and far more robust .NET applications. These refactorings pick up where the Migration Wizard leaves off.
by Danijel Arsenovski

September 18, 2006

Technology Toolbox: Visual Basic, ASP.NET, XML

Microsoft’s .NET initiative is tied closely with the concepts of SOA and Web services. Indeed, .NET was created with the intention of being an excellent environment for the development and use of service-based applications. However, companies often have to overcome a significant number of obstacles while trying to jump on .NET bandwagon, not the least of which is deciding what to do with their legacy code and legacy applications. These applications are often difficult to integrate into the service-oriented world.

ADVERTISEMENT

For example, there is still a huge amount of legacy VB code in operation. VB6 has proved to be an excellent tool for the rapid fabrication of components and COM-based development, but it lacks agility and productiveness when used for Web services development.

This brings us to a central pair of questions: What are your options if your operation still depends on a legacy code base, and what can you do to move closer to service-oriented architecture without abandoning your legacy code base completely?

You have three options available to you in this circumstance. First, you can stick with VB6 and your legacy VB code base. Second, you can use .NET-COM interoperability to create a “middle way.” This means keeping your COM components and using them from your newly developed .NET code. Third, you can move completely to .NET and upgrade your legacy VB code to VB.NET.

There are advantages and drawbacks to each of these choices; each organization needs to analyze all the options available to it, and then choose the path that best suits its requirements. Upgrading a VB6 application to .NET requires a lot of initial work and investment, but I think it is the winning option in the long run for most circumstances. The success of this option largely depends on your capacity to upgrade legacy code. But once the upgrade is performed, you have the latest technology and the most productive tools on the market at your disposal.

The third option—to move completely to .NET—is interesting for another reason: Many companies regard it as the most costly. However, approached correctly and with the right set of tools and techniques, upgrading VB6 code to .NET doesn’t have to be a daunting task.

Upgrading VB6 code to .NET does presents a number of challenges, but refactoring techniques can simplify many of them. Refactoring can give you the capacity to perform a full upgrade of your legacy code, and thus reap all the benefits of VB.NET and the .NET platform.

There is a downside: Upgrading to VB.NET is not a simple task, even with help from the Migration Wizard. First, Microsoft broke compatibility between VB6 and VB.NET in the process of preparing VB for the .NET platform. Some features in VB.NET are the direct result of Microsoft’s attempt to ease the path for upgrading from legacy VB code to .NET. Even so, you face a number of issues that aren’t easily resolved. In the end, you will have to finish manually the job the Migration Wizard started, writing some code yourself, before you can get a fully functional application that replicates the behavior of its legacy counterpart.

Once you migrate your application so it works correctly, you can say that the first half of your work is done. However, such an application requires more work before you can begin enjoying the advantages that the .NET Framework and the current version of VB.NET provide.

Fortunately, refactoring techniques give you an excellent tool for the second part of the task. Applying refactoring enables you to transform your recently migrated code, so it can harvest all the benefits of fully object-oriented, Statically-typed, .NET versions of Visual Basic.

What is Refactoring?
It might be helpful to take a quick look at what refactoring is, and how it can benefit you, before looking more closely at the ways you can use it to help migrate your code to .NET. According to Martin Fowler, author of well-known books on refactoring, “Refactoring is the process of changing a software system in such a way that it does not alter the external behaviour of the code, yet improves its internal structure.”

For example, assume you have a Purchase class:

Public Class Purchase
Private customer As Customer
Private items As List(Of PurchaseItem)

Public Function CalculateTotal() As Decimal
Dim total As Decimal = 0
For Each pItem As PurchaseItem In items
total += pItem.Price
Next
If (customer.NumberOfPurchases > 3) Then
total *= 0.97D
End If
Return total
End Function
End Class



Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
| | Discussions | Newsletters | FTP Home