Home > Articles > Programming > Visual Basic

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book


What Did This Chapter Cover?

This chapter described how to build code in the business logic layer for your application. It provided information on defining properties, coding methods, using generics, and building a base business object class.

This chapter covered several real productivity enhancers:

  • Writing class documentation using the XML documentation feature makes it easy to create the class's documentation. That documentation is then available in many places within Visual Studio, making it easier for you or your team to work with the class's properties and methods.
  • Defining regions helps you focus on the code you are working on.
  • Using partial classes for generated code makes it easier to regenerate the generated code without impacting the custom code.
  • Handling nulls using the generic Nullable structure simplifies working with value types and null values.
  • Defining a Factory pattern method or class library method with the Shared keyword makes it easy to call the method, because you don't need to create an instance of the class.
  • Building a base business object class provides standardized processing for all your application's business objects and significantly reduces the amount of housekeeping code required in each business object class.

The next chapter provides additional tools and techniques for working with classes.

Building Along

If you are "building along" with the Purchase Tracker sample application, this chapter added the basic code you need for your business object component.

Since the user interface from the preceding chapter does not yet reference any information in the business object component, running the application provides the same results as at the end of the preceding chapter.

The next chapter adds functionality and unit testing to the business object component of the Purchase Tracker sample application using some of the new Visual Studio 2005 tools and techniques.

Additional Reading

Cwalina, Krzysztof, and Brad Abrams. Framework Design Guidelines. Upper Saddle River, NJ: Addison Wesley, 2006.

This is an excellent book for any .NET developer. It provides general guidelines and many specific recommendations for handling everything from naming conventions to base classes to exceptions.

Lhotka, Rockford. Expert VB 2005 Business Objects, Second Edition. APress, 2006.

This book demonstrates how to build a framework for business objects that handles all the complex issues of .NET. It then shows you how to build Windows Forms, Web Forms, and Web Services interfaces on top of the objects, using all the data binding and other productivity features built into .NET 2.0 and Visual Studio 2005.

Richter, Jeffrey. "Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework." MSDN magazine, November 2000.

This article provides details on the .NET garbage collector.

Try It!

Here are a few suggestions for trying some of the techniques presented in this chapter:

  1. Add a SalesRep business object class to the business object Class Library project.

    Ensure that the class inherits from the base business object class. Add properties for name, employee number, and so on. Add a Create method using the same Factory pattern defined in this chapter. Add other methods as appropriate.

  2. Add an exception handler class, such as SalesRepNotFound-Exception, to the SalesRep class code file using an exception class.

    Throw the exception in the Create method if the ID passed into the method is not the ID you hard-coded data for.

  3. Add several overloads for the Create method in the SalesRep class.
  4. Make one of the overloads obsolete using the techniques presented in this chapter.
  • + Share This
  • 🔖 Save To Your Account