Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.

Similar presentations


Presentation on theme: "Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance."— Presentation transcript:

1 Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance

2 11 Chapter 11: Multiple Classes and Inheritance2 Objectives ►Use the TabIndex Property ►Edit input, including MaskedTextBox,TextBox, and ComboBox objects ►Describe the three-tier program structure ►Understand a class ►Create a class

3 11 Chapter 11: Multiple Classes and Inheritance3 Objectives ►Instantiate an object ►Pass arguments when instantiating an object ►Write a class constructor ►Call a procedure in a separate class

4 11 Chapter 11: Multiple Classes and Inheritance4 Objectives ►Code a base class and a subclass incorporating inheritance ►Call procedures found in a base class and a subclass ►Write overridable and overrides procedures ►Create and write a comma-delimited text file

5 11 Preview the Chapter Project Chapter 11: Multiple Classes and Inheritance5

6 11 Chapter 11: Multiple Classes and Inheritance6 User Interface and the TabIndex Property ►Select the object that will be selected when program execution begins. In the example, this is the txtStudentID MaskedTextBox object. Scroll in the Properties window until the TabIndex property is visible and then double-click in the right column of the TabIndex property ►Type 1 and then press the ENTER key ►Select the object which should be selected when the user presses the Tab key. In the sample program, the txtStudentName TextBox object should be selected. Double-click the right column of the TabIndex property for the txtStudentName TextBox object, type 2 and then press the ENTER key

7 11 Chapter 11: Multiple Classes and Inheritance7 User Interface and the TabIndex Property

8 11 User Interface and the TabIndex Property Chapter 11: Multiple Classes and Inheritance8

9 11 Chapter 11: Multiple Classes and Inheritance9 Editing Input Data ►Student ID: The student ID object is a masked text box and the mask is for the social security number, so the mask ensures that the user can enter only numbers. But, the social security mask does not ensure the user enters all nine numbers. Therefore, a check must be included in the program to require the user to enter all 9 numeric digits. ►Student Name: The program must ensure the user enters characters in this TextBox object. In addition, spaces cannot be entered instead of actual alphabetic characters. ►Number of Units: The user must enter a numeric value from 1 through 24 for the number of units the student is taking. ►Major: The user must select a major from the list in the Major ComboBox object.

10 11 Chapter 11: Multiple Classes and Inheritance10 Editing Input Data

11 11 Chapter 11: Multiple Classes and Inheritance11 Program Structure Using Classes ►The concept of separating processing and hiding data within specific classes is called encapsulation ►When developing programs with multiple classes, a starting point for determining what classes should appear in a program is the three-tier program structure

12 11 Chapter 11: Multiple Classes and Inheritance12 Program Structure Using Classes ►The presentation tier contains the classes that display information for the user and accept user input ►The business tier contains the logic and calculations that must occur in order to fulfill the requirements of the program ►The persistence tier, sometimes called the data access tier, contains the code required to read and write data from permanent storage

13 11 Chapter 11: Multiple Classes and Inheritance13 Sample Program Classes ►Presentation tier: The presentation tier contains the RegistrationCostForm class. This class displays the user interface in a Windows Form object and also edits the user input data to ensure its validity ►Business tier: The business tier contains two classes: the Student class and the OnCampusStudent class. The Student class contains data for each registered student and calculates the registration costs for some students. The OnCampusStudent class is used for registered students who live in oncampus residence halls ►Persistence tier: The persistence tier consists of one class, StudentCostsFile, which creates and writes the Student Costs File

14 11 Chapter 11: Multiple Classes and Inheritance14 Creating a Class ►With Visual Studio open and a Window Application project begun, right-click the project name in the Solution Explorer window and then point to Add on the shortcut menu ►Click Class on the Add submenu ►Type Student as the name of the class and then click the Add button ►Using the same techniques, create the OnCampusStudent class and the StudentCostsFile classes

15 11 Chapter 11: Multiple Classes and Inheritance15 Creating a Class

16 11 Creating a Class Chapter 11: Multiple Classes and Inheritance16

17 11 Chapter 11: Multiple Classes and Inheritance17 Instantiating a Class and Class Communication ►Whenever you define a class in your Visual Basic program, you must instantiate, or create, an object based on that class in order for the processing within the object to take place

18 11 Chapter 11: Multiple Classes and Inheritance18 Constructors in New Instantiated Classes ►When a class is instantiated into an object using the New keyword, a special procedure in the instantiated class called a constructor is executed ►The constructor prepares the object for use in the program

19 11 Chapter 11: Multiple Classes and Inheritance19 Passing Arguments when Instantiating an Object ►Often when instantiating an object, data must be passed to the object ►In the Student class, the New statement must be written with corresponding arguments; that is, the “signature” of the instantiating statement must be the same as the constructor heading in the class

20 11 Chapter 11: Multiple Classes and Inheritance20 Passing Arguments when Instantiating an Object

21 11 Chapter 11: Multiple Classes and Inheritance21 Calling a Procedure in a Separate Class ►Most of the time, separate classes in a program contain procedures that must be executed

22 11 Chapter 11: Multiple Classes and Inheritance22 Inheritance ►Inheritance allows one class to inherit attributes and procedures from another class

23 11 Chapter 11: Multiple Classes and Inheritance23 Inheritance

24 11 Chapter 11: Multiple Classes and Inheritance24 Inheritance

25 11 Chapter 11: Multiple Classes and Inheritance25 Constructors BASE CLASS CONSTRUCTOR

26 11 Chapter 11: Multiple Classes and Inheritance26 Constructors SUBCLASS CONSTRUCTOR

27 11 Chapter 11: Multiple Classes and Inheritance27 Inheritance and Procedures ►When using inheritance, the subclass can use the procedures within the base class as well as the variables within the base class ►Between the base class and the subclass, five different techniques for referencing and calling a procedure from an outside class such as a Form class can be used ►After the base class and the subclass have been instantiated, the following techniques are available:

28 11 Chapter 11: Multiple Classes and Inheritance28 Inheritance and Procedures ►Base Class Call a named procedure in the base class Call an Overridable procedure in the base class ►Subclass Call an Overridable Procedure in the subclass Call a named procedure in the subclass Call a base class procedure in the subclass

29 11 Call a Named Procedure in the Base Class Chapter 11: Multiple Classes and Inheritance29

30 11 Chapter 11: Multiple Classes and Inheritance30 Calling an Overridable Procedure in a Base Class

31 11 Calling an Overridable Procedure in a Subclass Chapter 11: Multiple Classes and Inheritance31

32 11 Calling a Named Procedure in the Subclass Chapter 11: Multiple Classes and Inheritance32

33 11 Calling a Base Class Procedure in the Subclass Chapter 11: Multiple Classes and Inheritance33

34 11 Chapter 11: Multiple Classes and Inheritance34 Persistence Classes ►The persistence tier in an application, sometimes called the data access tier, contains classes that are involved in saving and retrieving data that is stored on a permanent storage medium such as a hard disk, a DVD-ROM or a USB drive

35 11 Chapter 11: Multiple Classes and Inheritance35 Persistence Classes

36 11 Chapter 11: Multiple Classes and Inheritance36 Comma-Delimited Text File

37 11 Chapter 11: Multiple Classes and Inheritance37 Comma-Delimited Text File

38 11 Chapter 11: Multiple Classes and Inheritance38 Program Design

39 11 Chapter 11: Multiple Classes and Inheritance39 Program Design

40 11 Chapter 11: Multiple Classes and Inheritance40 Program Design

41 11 Chapter 11: Multiple Classes and Inheritance41 Event Planning Document

42 11 Chapter 11: Multiple Classes and Inheritance42 Event Planning Document

43 11 Chapter 11: Multiple Classes and Inheritance43 Event Planning Document

44 11 Chapter 11: Multiple Classes and Inheritance44 Event Planning Document

45 11 Chapter 11: Multiple Classes and Inheritance45 Event Planning Document

46 11 Chapter 11: Multiple Classes and Inheritance46 Event Planning Document

47 11 Chapter 11: Multiple Classes and Inheritance47 Summary ►Use the TabIndex Property ►Edit input, including MaskedTextBox,TextBox, and ComboBox objects ►Describe the three-tier program structure ►Understand a class ►Create a class

48 11 Chapter 11: Multiple Classes and Inheritance48 Summary ►Instantiate an object ►Pass arguments when instantiating an object ►Write a class constructor ►Call a procedure in a separate class

49 11 Chapter 11: Multiple Classes and Inheritance49 Summary ►Code a base class and a subclass incorporating inheritance ►Call procedures found in a base class and a subclass ►Write overridable and overrides procedures ►Create and write a comma-delimited text file

50 Microsoft Visual Basic 2008 CHAPTER ELEVEN COMPLETE Multiple Classes and Inheritance


Download ppt "Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance."

Similar presentations


Ads by Google