Skip to main content

Professional Refactoring in Visual Basic

Professional Refactoring in Visual Basic

Danijel Arsenovski

ISBN: 978-0-470-37254-8

Mar 2008

517 pages

Select type: E-Book

Product not available for purchase


In this one-of-a-kind book, Microsoft MVP Danijel Arsenovski shows you how to utilize the power of refactoring to improve the design of your existing code and become more efficient and productive. You?ll discover how to perform unit testing, refactoring to patterns, and refactoring to upgrade legacy Visual Basic code. As you progress through the chapters, you?ll build a prototype application from scratch as Arsenovski walks you step-by-step through each process while offering expert coding tips.

Part I: Introduction to Refactoring.

Chapter 1: Refactoring: What’s All the Fuss About?

Chapter 2: A First Taste of Refactoring.

Chapter 3: Assembling a Refactoring Toolkit.

Chapter 4: Rent-a-Wheels Application Prototype.

Part II: Preliminary VB Refactorings.

Chapter 5: Chameleon Language: From Weak Static Typing to Strong Dynamic Typing.

Chapter 6: Error Handling: From Legacy to Structured in a Few Easy Steps.

Chapter 7: Basic Hygiene: Eliminating Dead Code, Reducing Scope, Using Explicit Imports, and Removing Unused References.

Part III: Getting Started with Standard Refactoring Transformations.

Chapter 8: From Problem Domain to Code: Closing the Gap.

Chapter 9: The Method Extraction Remedy for Duplicated Code.

Chapter 10: Method Consolidation and Extraction Techniques.

Part IV: Advanced Refactorings.

Chapter 11: Discovering Objects.

Chapter 12: Advanced Object-Oriented Concepts and Related Refactorings.

Chapter 13: Code Organization on a Large Scale.

Part V: Refactoring Applied.

Chapter 14: Refactoring to Patterns.

Chapter 15: LINQ and Other VB 2008 Enhancements.

Chapter 16: The Future of Legacy VB Code.

Appendix A: Unleash Refactor!

Appendix B: Rent-a-Wheels Prototype Internals and Intricacies.


Code Downloads
All code from the book
Code downloads for this title are available here.
Code Downloads
All code from the book
Code downloads for this title are available here.
ChapterPageDetailsDatePrint Run
274Error in Image
Image is not correct. It shows an object model, not a refactoring at work.

294Error in Image
Image is not correct. It shows an app design, not a CRC card.

11311-313Error in Code Listing 11-5
ViewAccountDetails_Click routine in ViewAccount class should say:

Private Sub ViewAccountDetails_Click(ByVal sender As System.Object,_

ByVal e As System.EventArgs) Handles ViewAccountDetails.Click

Dim accountData As AccountData = New AccountData()

Dim account As Account = accountData.GetAccount(Me.Number.Text)

Me.Name.Text = account.Name

Me.Type.Text = account.Type.TypeName

If Not account.Blocked Then

Me.Balance.Text = account.Balance


Me.Balance.Text = Blocked

End If

End Sub

GetAccount routine in AccountData class should say:

Public Function GetAccount(ByVal number As String) As Account

Dim connection As IDbConnection = _

New SqlConnection(ConnectionString)

Dim adapter As IDbDataAdapter = New SqlDataAdapter

Dim accountDataSet As New DataSet

Dim command As IDbCommand = New SqlCommand

Dim strSql As String = Select * from Accounts + _

where Name = + number


command.Connection = connection

command.CommandText = strSql

adapter.SelectCommand = command



accountTable = accountDataSet.Tables.Item(0)

Dim accountRow As DataRow = _


Dim account As New Account( _

accountRow.Item( Number ).ToString(), _

accountRow.Item( Name ).ToString(), _

New AccountType(accountRow.Item( Type ).ToString()), _

CDec(accountRow.Item( Balance )), _

CBool(accountRow.Item( Blocked )))

Return account

End Function

15447Error in Code Listing 11-5
Sidebar ?Refactoring: Replace Complex VB Queries with LINQ? Before and After code sections should say:


Dim authorWithMostBooks As Author = Nothing

For Each author In authors

If authorWithMostBooks Is Nothing OrElse _

author.Books.Count > authorWithMostBooks.Books.Count Then

authorWithMostBooks = author

End If



Dim authorWithMostBooks = (From author In authors _

Order By author.Books.Count Descending _

Select author).First