Beginning Visual Basic 2005 (2006)
.pdf12
Building Class Libraries
In this chapter, you’re going to look at building libraries of classes. This will gather together many of the concepts you’ve learned in this book, so let’s have a quick review. So far, you’ve learned a lot about developing Windows Applications by dragging controls onto forms, editing their properties, and adding code. When you edit a form in the Form Designer, you are actually designing a new class that inherits from the System.Windows.Forms.Form class.
When you make changes to the form in the designer, the designer works out what code needs to be added to the class. You can view this code by clicking the Show All Files icon in the Solution Explorer and then opening the designer-generated code for your form. When you run the program, an instance of this class is created — an object. Like most objects, the form has state and behavior — you can have variables and controls on the form (state) and you can perform actions when, for example, the user clicks a button on the form (behavior). In theory, you could write your forms without using the designer at all; very few programmers work this way while creating Windows forms.
Right from the start you’ve been creating classes. You’ve also looked at creating your own classes from scratch. Recall what you studied about building objects in Chapter 10, where you created a project called Objects, which contained the classes Car and SportsCar. These classes were used in a console application because it made the objects easier to test, but they would have worked just as well in a Windows application. You could even have used them in a Web application or Web Service. In fact, one of the key benefits of using classes is that once you’ve designed a good one, you can use it over and over again in different applications.
In this chapter, you will:
Create your own class libraries and learn how to get information about existing libraries that are not part of the .NET Framework
Learn to assign strong-name assemblies (compiled files) to ensure that all assemblies have a unique identity
Register assemblies in a repository called the Global Assembly Cache (GAC) so that they can be shared between applications on the same computer