DOC PREVIEW
UCR CS 5 - Chapter 10 Advanced Object-Oriented Programming

This preview shows page 1-2-3-25-26-27-28-50-51-52 out of 52 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 10 – Advanced Object-Oriented ProgrammingSlide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52The Visual Basic .NET Coach1Chapter 10 – Advanced Object-Oriented ProgrammingEverything in Visual Basic .NET is considered an object. When everything is an object, it allows you to create new objects from the existing objects. If the objects that come with Visual Basic .NET do not meet your needs, you do not have to start from scratch. Instead, you can start with an object that contains the majority of the functionality you require and create a new object that inherits the original object’s functionality but also contains the additional information.The Visual Basic .NET Coach210.1 Visual InheritanceAs you develop applications you will find that your objects are required in more than one application. Often the object will require modifications in order for it to work properly in the new application. While you can just copy the code associated with the object to the new application and then modify it there, this would cause a number of potential problems.A minor problem is that you are wasting space on your hard drive. If you have the definition in numerous places, you will have to make the correction in numerous places.Chapter 10 – Advanced Object-Oriented ProgrammingThe Visual Basic .NET Coach3Inheritance is the ability to create one object from another. With inheritance you will create a simple class to define an object that will be common to many other objects and then create other classes based on the original class, but with more features.The original class is known as the base class, The classes created from the base class are known as derived classes.Visual Basic .NET not only allows you to code classes with inheritance, but you can also inherit visually. Visual inheritance allows the developer to inherit forms and controls to create new forms and controls.Chapter 10 – Advanced Object-Oriented ProgrammingThe Visual Basic .NET Coach4With visual inheritance you can create the form that all forms are to model and then tell Visual Basic .NET that you wish to create a form based on the original form. With visual inheritance, if you make a change to the original form, all that is required is that you rebuild your applications and the applications will automatically update themselves to reflect any changes to the base form.To create a form that inherits its properties from a previous existing form, like the one just discussed, you should follow these steps:Step 1: Create a form, frmBase, with a logo in the upper-left corner and a copyright in the lower-left corner:Chapter 10 – Advanced Object-Oriented ProgrammingThe Visual Basic .NET Coach5Step 2: Select Add Inherited Form from the Project menu.Step 3: Select Open from the dialog box that appears:Chapter 10 – Advanced Object-Oriented ProgrammingThe Visual Basic .NET Coach6Step 4: Select InheritedForm from the Templates. It should be the default. Change the Name of the form from Form1.vb to the name you wish your new form to be called. You will use frmDerived.vb for this example. Click on the Open button. The dialog box shown here will appear.Chapter 10 – Advanced Object-Oriented ProgrammingThe Visual Basic .NET Coach7Step 5: Select frmBase as the form you wish to base your new form on. Click on the OK button and your new form should appear and look similar to the base form that you created it from:Chapter 10 – Advanced Object-Oriented ProgrammingNotice the small arrows on the label and picture box that were inherited from the base form. This is your way of differentiating the objects you have added to the derived form versus the objects you have inherited from the base form.The Visual Basic .NET Coach8Visual inheritance applies to any controls or code that you include in a base class or object.Imagine if you created a single form containing the common demographic data for people. You could create a form with controls to gather the person’s first name, middle initial, last name, street address, city, state, ZIP code, email address, and so on. Then additional forms could inherit from this form the basic information and add the information pertinent to the specific group they belonged to. The code associated with the basic information could also be contained in the base form and added to the derived forms.This allows you to modify the basic demographic information in one place and again have it propagate through all the company’s applications with a minimum of effort. Visual inheritance is an excellent way to enforce uniformity across a company.Chapter 10 – Advanced Object-Oriented ProgrammingThe Visual Basic .NET Coach910.2 Inheritance in CodeProtected KeywordA property defined with the Private keyword allows only methods and events of the class the property is defined in to have access to it. In contrast, a property defined with a scope of Public allowed any routine to have access to it.When a base class is going to be inherited, you’ll want the properties of the base class to be accessible by methods of the derived class. In these cases, you will need to define a property with a scope of Protected.If you attempt to access an attribute in a base class from a derived class that is defined with a Private scope, it will not be accessible from methods in the derived class.The syntax for declaring a property with a Protected scope is as follows:Chapter 10 – Advanced Object-Oriented ProgrammingProtected PropertyName As DataTypeThe Visual Basic .NET Coach10Overriding Methods Defined in a Base ClassWhen a method is defined in a base class, you can decide whether or not that method can be changed in the derived class. Allow the overriding of a method in the derived classes. You must add the Overridable keyword to the base class method definition:Chapter 10 – Advanced Object-Oriented ProgrammingPublic Overridable Function MethodName(ParameterName As Datatype) As Datatype 'Body of MethodEnd FunctionPublic Overridable Sub MethodName(ParameterName As Datatype) 'Body of MethodEnd SubThe Visual Basic .NET Coach11Defining a Derived ClassTo define a new class that is


View Full Document

UCR CS 5 - Chapter 10 Advanced Object-Oriented Programming

Download Chapter 10 Advanced Object-Oriented Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 10 Advanced Object-Oriented Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 10 Advanced Object-Oriented Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?