Manage Learn to apply best practices and optimize your operations.

Chapter 5: 'Building the business logic layer'

This chapter is all about classes. Learn how to create classes and document them with XML, how to go about adding exception classes, defining properties and different methods for handling parameters, among other topics. Check it out today!


Download chapter 5: 'Building the business logic layer'


Excerpted from the book "Doing Objects in Visual Basic 2005," ISBN 0-321-32049-2, Copyright 2007. Written permission from Addison-Wesley is required for all other uses. Copyright © 2006 Addison-Wesley. All rights reserved.







Chapter Excerpt:


Adding a Class to a Project

When building the business logic layer, you normally add one class project item for each business object class (such as Product and Customer) and one for each implementation class (such as Logging and Security).

To add a class to a project:
  1. Right-click the project in Solution Explorer and select Add | New Item from the context menu, or select Project | Add New Item from the main menu bar. Alternatively, you could select Add | Class from the context menu, or select Project | Add Class from the main menu bar.
  2. Select the Class template, name the class, and click the Add button.


If you created your own class template using the steps in Chapter 3, you can use your template here.

Use standard naming conventions for your class name. The most common standard is to name the class using the singular name of the business entity or implementation feature represented by the class. For products the class name would be Product, for logging the class name would be Logging, and so on.

Visual Studio creates the class file with a .vb extension, adds it to Solution Explorer, and then displays the class in the Code Editor.

When Visual Studio creates the class file, it automatically generates the class declaration as follows:



Public Class Product

End Class

You can add any number of classes to your projects as needed by your application. Regardless of the class's purpose or location, the basic process of building a class is the same.


Documenting the Class

It is always a good idea to add documentation for a class immediately after adding the class. By adding the documentation right away, you focus on the class's purpose, which helps you keep the class encapsulated. It is also much easier to document each class as you go along instead of facing the large task of going back later and documenting all the classes.
To document the class:
  1. Open the class in the Code Editor.
  2. Move the insertion point immediately before the word Public in the Public Class statement.
  3. Type three comment markers, defined in Visual Basic as apostrophes ('''), and press the Enter key. The XML comments feature automatically creates the structure of your class documentation as follows:
    
    ''' <summary>
    '''
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Product
    
    End Class
    

4. Type a summary of the class's purpose between the summary tags and any remarks between the remark tags. Your documentation may be similar to this:

''' <summary>
''' Provides product management features such as
''' retrieving product data and saving product changes
''' </summary>
''' <remarks>Use this class to work with products
''' </remarks>

Use the summary tags to describe the class and the remarks tags to add supplemental information. The summary is the most important tag because it is the one used by Visual Studio. When you provide a summary of the class using XML comments, your class displays documentation about itself in appropriate places within Visual Studio, such as in the List Members box, shown in Figure 5.1. Open the List Members box by typing a part of the class name in the Code Editor and pressing Ctrl+Spacebar or by selecting Edit | Intellisense | List Members from the main menu bar or by clicking the Display an Object Member List icon on the Text Editor toolbar.

Using XML comments to document your classes makes it easier for you and other developers to work with your classes.



Chapter 5: 'Building the business logic layer'

Visit the Addison-Wesley website for a detailed description and to learn how to purchase this title.

There are many ways to add a class to a project. As discussed in the preceding chapter, adding a form project item actually adds two class files to the project. It adds a class in one file with a .vb extension and a partial class in another file with a .designer.vb extension.
This was last published in March 2007

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close