[ Pobierz całość w formacie PDF ]
.If an application is searching for version 2.1.4.0 ofHealthcare, the Administration policy file can point the application to another ver-sion, forcing an upgrade or downgrade.SummaryCreating classes (or objects) is one of the most common things for a VB developerto do.Class creation is different in VB.NET, as you can tell from this chapter.Itchanges much more when you start looking at inheritance, as you will in the nextchapter.The main differences are how you create properties, how you handle read-only, write-only, and default properties, and how you can handle events.There is also a big dif-ference in the fact that you compile assemblies instead of COM components.Finally,the way files are located is also very different.There is an important concept in dealing with assemblies that is not covered due totime and size constraints, and that is how assemblies handle versioning.Look for thisinformation in an updated book after Visual Studio.NET is released. 06 2203-x CH05 5/25/01 9:58 AM Page 91CHAPTER 5Inheritance with VB.NETWhat Is Inheritance?For years, one of the most requested features from VisualBasic developers was inheritance.Microsoft has had oneform of inheritance, interface inheritance, available in VB forseveral years.Developers, however, wanted to have what isknown as implementation inheritance.With VB.NET, devel-opers finally get their wish, thanks to the CLR.And, if you reunclear on what interface and implementation inheritance are,read on.Inheritance is a very powerful form of code reuse.Withinheritance, you write one class that contains some propertiesand methods.That class becomes the basis for other classes,and is known as the base class.Classes that then use thisbase class are known as derived classes.Most often, thederived classes extend the functionality of the base class.Imagine if you wanted to create an application to model partof a university.As part of your application, you wanted tocreate two objects, representing students and professors.Students and professors both have a number of things incommon: Each has a name, an address, and so forth.How-ever, each also has some differences.Students have declaredmajors, whereas professors have classes they can teach.Students are charged tuition, whereas professors are paidfor their work.Professors submit grades, whereas studentsreceive them.Inheritance with VB.NET 06 2203-x CH05 5/25/01 9:58 AM Page 9292 Chapter 5: I nheri tance wi th VB.NETAs you can see, there are similarities and differences that must be taken into accountwhen these objects are built.The goal of inheritance is to write the code for the simi-larities once, and then use it in both the Student and Professor objects.Interface Inheritance in VB6In VB6, you had what was called interface inheritance.With interface inheritance,you could create the interface (or shell, or definition) of a reusable component.Suppose that you wanted to create a Person object that had all the shared attributesof both students and professors.In the case of VB6, you would create a class modulethat contained the definitions of those attributes, but no actual code.Your interfaceclass might be named iPerson and look like this:Public Property Get Name() As StringEnd PropertyPublic Property Let Name(psName As String)End PropertyPublic Property Get Address() As StringEnd PropertyPublic Property Let Address(psAddress As String)End PropertyPublic Function Enroll() As BooleanEnd FunctionIn VB6, you could create an interface using a class module.Technically, VB couldnot create interfaces, but you could use the hack of creating a class module with onlydefinitions for properties and methods, and then implement it in another class.Thiswas actually just creating a class, but there would be no implementation code in it, soit  looked like an interface.For example, the Enroll method does not have any codeto actually handle the enrollment.And if you are curious why there is an Enrollfunction in the iPerson interface, it is because professors can also take courses at theuniversity, which some do because they can do so for free at most institutions.To use this interface in other classes in VB6, you had to put this line of code in yourclass:Implements iPersonThis line set up your new class to inherit the interface from the iPerson class.InVB6, you could actually put implementation code into the interface class, but it wasignored when you implemented the interface in your derived class. 06 2203-x CH05 5/25/01 9:58 AM Page 93What I s I nheri tance? 93Imagine that you have used the Implements keyword in a class named cStudent.This class must now implement every public property, method, and event found iniPerson [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • personata.xlx.pl