Download presentation
Presentation is loading. Please wait.
Published byMadlyn Daniel Modified over 9 years ago
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 a Masked TextBox, TextBox, and ComboBox objects ►Describe the three-tier program structure ►Understand a class [ Abstract Data Type ] ►Create a class ►VisualBasic Methods are implemented using: Sub procedures Function procedures
3
11 Chapter 11: Multiple Classes and Inheritance3 Objectives ►Instantiate a class [ create an object ] ►Pass arguments when instantiating an object ►Write a class constructor ►Call a method in an object [ or Class if Shared ]
4
11 Chapter 11: Multiple Classes and Inheritance4 Objectives ►Using inheritance, code a base class and a subclass [derived class] ►Call procedures [methods] found in a base class and a subclass ►Create an overridable method ►Create an overridden method by using the keyword overrides ►Create and write a comma-delimited text file
5
11 Chapter 11: Multiple Classes and Inheritance5 Chapter Project
6
11 Chapter 11: Multiple Classes and Inheritance6 User Interface and the TabIndex Property ►Select txtStudentID MaskedTextBox object. ►Set the TabIndex property to 1 ►Select the object which should be selected when the user presses the Tab key. ►Select txtStudentName TextBox object. ►Set the TabIndex property to 2
7
11 Chapter 11: Multiple Classes and Inheritance7 User Interface and the TabIndex Property
8
11 Chapter 11: Multiple Classes and Inheritance8 Editing Input Data [validation] ►Student ID: The student ID object is a masked textbox 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
9
11 Chapter 11: Multiple Classes and Inheritance9 Editing Input Data
10
11 Chapter 11: Multiple Classes and Inheritance10 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 GUI Problem Domain Data Access Business Logic
11
11 Chapter 11: Multiple Classes and Inheritance11 Program Structure Using Classes ►presentation tier: contains the classes that display information for the user and accept user input ►business tier contains the logic and calculations that must occur in order to fulfill the requirements of the program ►persistence tier sometimes called the data access tier, contains the code required to read and write data from permanent storage
12
11 Chapter 11: Multiple Classes and Inheritance12 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. ►Student class contains data for each registered student and calculates the registration costs for some students. ►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
13
11 Chapter 11: Multiple Classes and Inheritance13 Creating a Class ►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
14
11 Chapter 11: Multiple Classes and Inheritance14 Creating a Class
15
11 Chapter 11: Multiple Classes and Inheritance15 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
16
11 Chapter 11: Multiple Classes and Inheritance16 Constructors ►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 ►Every class has a constructor. ►If no constructor was created by the programmer, VisualBasic.NET provides a “default” constructor that doesn’t do anything…
17
11 Chapter 11: Multiple Classes and Inheritance17 Constructors ►VisualBasic permits “overloaded” constructors just as it permits overloaded function and sub procedures ►Below is a “default” aka “no-argument” constructor
18
11 Chapter 11: Multiple Classes and Inheritance18 Using a parameterized constructor ►Often when instantiating an object, data must be passed to the object when it is created. ►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
19
11 Chapter 11: Multiple Classes and Inheritance19 Passing Arguments to a Constructor when Instantiating an Object
20
11 Chapter 11: Multiple Classes and Inheritance20 Calling a Procedure in a Different Object ►Most of the time, separate objects in a program contain procedures [methods] that must be executed
21
11 Chapter 11: Multiple Classes and Inheritance21 Inheritance ►Inheritance allows one class to inherit attributes and behaviors from another class ►Attributes: variables ►Behaviors: methods Subclass ResidenceHall
22
11 Chapter 11: Multiple Classes and Inheritance22 Inheritance Permissible Access Modifiers: Public, Private, Protected, Friend
23
11 Chapter 11: Multiple Classes and Inheritance23 Inheritance [ General ----> Specific ] The Inherits keyword precedes the name of the superclass for a subclass. Remember, you inherit variables and methods.
24
11 Chapter 11: Multiple Classes and Inheritance24 Constructors BASE CLASS CONSTRUCTOR [ Student ]
25
11 Chapter 11: Multiple Classes and Inheritance25 Constructors SUBCLASS CONSTRUCTOR [ OnCampusStudent ] MyBase is a referece to the superclass of the base class. This is similar to the reference Me by which a class [object] refers to itself.
26
11 Chapter 11: Multiple Classes and Inheritance26 Inheritance and Procedures [Methods] ►When using inheritance, the subclass can use the procedures and variables inherited from the base class [ must be public/protected ]
27
11 Chapter 11: Multiple Classes and Inheritance27 Inheritance and Procedures [ Methods ] ►A method in a class can call other methods in the same class or public/protected inherited methods from its superclass. ►An Overridable method is a method which can be overridden in a subclass [ the implementation can be changed… ] ►To override an “overridable” method in a subclass you use the keyword Overrides in the method signature. Overriding is optional.
28
11 Chapter 11: Multiple Classes and Inheritance28 Creating an Overridable Method
29
11 Chapter 11: Multiple Classes and Inheritance29 Creating an Overrides Method [ subclass ]
30
11 Chapter 11: Multiple Classes and Inheritance30 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
31
11 Chapter 11: Multiple Classes and Inheritance31 Persistence Classes
32
11 Chapter 11: Multiple Classes and Inheritance32 Comma-Delimited Text File
33
11 Chapter 11: Multiple Classes and Inheritance33 Comma-Delimited Text File
34
11 Chapter 11: Multiple Classes and Inheritance34 Program Design
35
11 Chapter 11: Multiple Classes and Inheritance35 Program Design
36
11 Chapter 11: Multiple Classes and Inheritance36 Program Design
37
11 Chapter 11: Multiple Classes and Inheritance37 Event Planning Document
38
11 Chapter 11: Multiple Classes and Inheritance38 Event Planning Document
39
11 Chapter 11: Multiple Classes and Inheritance39 Event Planning Document
40
11 Chapter 11: Multiple Classes and Inheritance40 Event Planning Document
41
11 Chapter 11: Multiple Classes and Inheritance41 Event Planning Document
42
Microsoft Visual Basic 2008 CHAPTER 11 COMPLETE Multiple Classes and Inheritance
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.