What Is an Object?

Using Project Templates

It seems as though software development these days is largely focused on reuse. Programming with objects is one of the hottest topics for programmers, and objects are really all about code reuse. It only makes sense that if you can take advantage of previous development by using some or all of an existing object, you can reduce development and testing time. Creating object templates as I discussed at the beginning of this chapter is a great way to make common objects easily accessible to new and existing projects. In addition to enabling you to make object templates, Visual Basic .NET also gives you the ability to create complete project templates.

Creating Custom Project Templates

Project templates can be skeletal templates containing a few base objects, such as a form and a class, or they can be half-completed applications containing intricate code, such as a multiple-document interface (MDI) front end. To see examples of project templates, you need go no further than starting up Visual Basic .NET itself and creating a new project, as shown in Figure 1-3.

Figure 1-3. Visual Basic .NET includes a number of predefined project types.

graphics/f01ln03.jpg

The default project templates displayed in the New Project dialog box are installed with Visual Basic .NET. These project templates are stored in a Microsoft .NET wizard format (.vsz). Creating such wizards is beyond the scope of this book. However, you don't have to know how to create wizards in order to create project templates of your own.

To create a project template, create a new subfolder in the \Microsoft Visual Studio .NET\Vb7\VBProjects folder see Figure 1-4 and place a copy of the project that you want to use as a template in that folder. The subfolders that you create here appear as subfolders of the Visual Basic Projects folder in the New Project dialog box. (See Figure 1-5.)

Tip

Because every module (including form modules) should have full error trapping (as I'll discuss in Chapter 10, "Exception Handling"), you should add the proper error handling to each object template in the project. The idea is to make each object template as complete as possible. If objects based on a common template need to have the same work done to them each time they're added to a project, that work should be done in the template file itself.


 

Figure 1-4. To create a project template, place the project files in a new subfolder of the \VBProjects folder.

graphics/f01ln04.jpg

Figure 1-5. Custom project templates appear in their folders under the Visual Basic Projects folder in the New Project dialog box.

graphics/f01ln05.jpg

Note

You don't need to include the solution file or the \Bin or \Obj folders when placing a project in the \VBProjects folder. If you don't copy the solution file, however, Visual Basic .NET will prompt you to create one if you open and modify the project.


 

When you double-click a project template icon in the New Project dialog box, Visual Basic .NET creates a temporary copy of the corresponding template project files. When you save the project, Visual Basic .NET asks you to name all the objects within the project as well as the project itself. This behavior is much the same as when you are adding objects based on templates to a project Visual Basic .NET never overwrites the original template files.

To modify a custom project template, you must open the projects directly. (Don't create a new project based on the template.) When you open a template project directly, rather than create a new project based on the template, Visual Basic .NET treats the template project like any other project. When you save changes, the actual template files are overwritten with your modifications. This is a great way to tweak standard project templates so that they're more immediately usable in your environment.

Note

If you didn't copy the project's solution file to your custom template folder, Visual Basic .NET will prompt you to create one when editing the template project.


 

 

Goals of Using Object and Project Templates

The primary goals of using object and project templates include

  • Promoting and encouraging code reuse

  • Reducing development time of new and existing projects

 



Practical Standards for Microsoft Visual Basic. NET
Practical Standards for Microsoft Visual Basic .NET (Pro-Developer)
ISBN: 0735613567
EAN: 2147483647
Year: 2005
Pages: 84

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net