Section 11.9. Wrap-Up


11.9. Wrap-Up

In this chapter we discussed polymorphism, which enables you to "program in the general" rather than "program in the specific," and we showed how this makes programs more extensible. We began with an example of how polymorphism would allow a screen manager to display several "space" objects. We then demonstrated how base class and derived class references can be assigned to base class and derived class variables. We said that assigning base class references to base class variables is natural, as is assigning derived class references to derived class variables. We then discussed MustOverride methods (methods that do not provide an implementation) and MustInherit classes (abstract classes that typically have one or more MustOverride methods). You learned that abstract classes cannot be used to instantiate objects, whereas concrete classes can. We showed how abstract classes are used in an inheritance hierarchy. You learned that assigning derived class references to base class variables is natural because a derived class object is an object of its base class. You learned why assigning base class references to derived class variables is dangerous and why the compiler disallows such assignments (when Option Strict is On). We introduced late binding, which enables the proper methods to be called when objects at various levels of an inheritance hierarchy are referenced at execution time via base class variables. You also learned how to determine the type of an object at execution time by using a TypeOf...Is expression; you then can use tryCast to downcast from the base class type to the derived class type. You learned how interfaces even allow objects of unrelated classes to be processed polymorphically. Objects of classes that implement the same interface have an is-a relationship with the interface type. Finally, the chapter discussed how to declare and implement an interface.

You have studied classes, objects, encapsulation, inheritance, interfaces and polymorphismthe most essential aspects of object-oriented programming. In the next chapter, you will learn about exceptions, which are useful for handling errors during a program's execution, thus creating more robust programs.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

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