Multiple Classes and Inheritance

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Advertisements

1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2012 CHAPTER ONE Introduction to Visual Basic 2012 Programming.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
Microsoft Visual Basic 2005 CHAPTER 12 Cell Phone Applications and Web Services.
A First Program Using C#
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2005: Reloaded Second Edition
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 2 The Visual Basic.NET Integrated Development Environment.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Office 2013 and Windows 8: Essential Concepts and Skills Microsoft Office 2013.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 2 The Visual Basic.NET Integrated Development Environment.
Microsoft Visual Basic 2015 CHAPTER ONE Introduction to Visual Basic 2015 Programming.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Learning With Computers I (Level Green) ©2012 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 12 Creating Console Applications, Understanding XML, and Creating Web Services.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
Windows 7 and file management
Getting Started with Application Software
Chapter 1: An Introduction to Visual Basic 2015
Introduction to Visual Basic 2008 Programming
Variables and Arithmetic Operations
3.01 Apply Controls Associated With Visual Studio Form
Incorporating Databases with ADO.NET
Program and Graphical User Interface Design
1. Introduction to Visual Basic
CHAPTER FIVE Decision Structures.
Visual programming Chapter 1: Introduction
3.01 Apply Controls Associated With Visual Studio Form
Using Procedures and Exception Handling
Microsoft Excel 2007 – Level 1
Program and Graphical User Interface Design
Incorporating Databases with ADO.NET
Chapter 7 Advanced Form Techniques
CHAPTER FIVE Decision Structures.
Variables and Arithmetic Operations
MODULE 7 Microsoft Access 2010
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
CIS16 Application Development Programming with Visual Basic
Programming with Microsoft Visual Basic 2008 Fourth Edition
Integrating JavaScript and HTML
Chapter 2 Creating a Research Paper with References and Sources
Lecture Set 11 Creating and Using Classes
CIS16 Application Development and Programming using Visual Basic.net
Shelly Cashman: Microsoft Excel 2016
Presentation transcript:

Multiple Classes and Inheritance CHAPTER ELEVEN Multiple Classes and Inheritance

Objectives Use the TabIndex Property Edit input, including MaskedTextBox,TextBox, and ComboBox objects Describe the three-tiered program structure Understand a class Create a class Chapter 11: Multiple Classes and Inheritance © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

Objectives Instantiate an object Pass arguments when instantiating an object Write a class constructor Call a procedure in a separate class Chapter 11: Multiple Classes and Inheritance © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

Objectives Code a base class and a subclass to incorporate inheritance Call procedures found in a base class and a subclass Write overridable and overrides procedures Create and write a comma-delimited text file Chapter 11: Multiple Classes and Inheritance

Use the TabIndex Property in the User Interface Select the object that will be selected when program execution begins. Scroll in the Properties window until the TabIndex property is visible and then double-tap or 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. Double-tap or double-click the right column of the TabIndex property for the object, type 2 and then press the ENTER key Chapter 11: Multiple Classes and Inheritance

Use the TabIndex Property in the User Interface Chapter 11: Multiple Classes and Inheritance

Editing Input Data Student ID: The Student ID object is a masked text box, and the mask is for the Social Security number in the same layout, so the mask ensures that the user can enter only numbers. However, the Social Security mask does not ensure that the user enters all nine numbers. Therefore, a check must be included in the program to require the user to enter all nine numeric digits Student Name: The program must ensure that 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 Chapter 11: Multiple Classes and Inheritance

Editing Input Data Chapter 11: Multiple Classes and Inheritance

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 Chapter 11: Multiple Classes and Inheritance

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 Chapter 11: Multiple Classes and Inheritance

Sample Program Classes Presentation tier: The presentation tier contains the frmCollege class. This class displays the user interface in a Windows Form object and 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 on-campus residence halls Persistence tier: The persistence tier consists of one class, StudentCostsFile, which creates and writes the Student Costs File Chapter 11: Multiple Classes and Inheritance

Creating a Class With Visual Studio open and a new Windows Application project started, press and hold or right-click the project name in the Solution Explorer window and then point to Add on the shortcut menu Tap or click Class on the Add submenu In the Name text box, type Student as the name of the class and then tap or click the Add button Using the same techniques, create the OnCampusStudent class and the StudentCostsFile class Chapter 11: Multiple Classes and Inheritance

Creating a Class Chapter 11: Multiple Classes and Inheritance

Instantiating a Class and Class Communication A class acts as a template for an object Chapter 11: Multiple Classes and Inheritance

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

Passing Arguments when Instantiating an Object When you instantiate an object, data often 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 Chapter 11: Multiple Classes and Inheritance

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

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

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

Inheritance Chapter 11: Multiple Classes and Inheritance

Inheritance Chapter 11: Multiple Classes and Inheritance

Base Class Constructor Chapter 11: Multiple Classes and Inheritance

Subclass Constructor Chapter 11: Multiple Classes and Inheritance

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

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 Chapter 11: Multiple Classes and Inheritance

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

Calling an Overridable Procedure in a Base Class Need 11-30b Chapter 11: Multiple Classes and Inheritance

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

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

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

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

Persistence Classes Chapter 11: Multiple Classes and Inheritance

Comma-Delimited Text File Chapter 11: Multiple Classes and Inheritance

Comma-Delimited Text File Chapter 11: Multiple Classes and Inheritance

Program Design Chapter 11: Multiple Classes and Inheritance

Program Design Chapter 11: Multiple Classes and Inheritance

Program Design Chapter 11: Multiple Classes and Inheritance

Event Planning Document Chapter 11: Multiple Classes and Inheritance

Event Planning Document Chapter 11: Multiple Classes and Inheritance

Event Planning Document Chapter 11: Multiple Classes and Inheritance

Event Planning Document Chapter 11: Multiple Classes and Inheritance

Event Planning Document Chapter 11: Multiple Classes and Inheritance

Event Planning Document Chapter 11: Multiple Classes and Inheritance

Summary Use the TabIndex Property Edit input, including MaskedTextBox,TextBox, and ComboBox objects Describe the three-tiered program structure Understand a class Create a class Chapter 11: Multiple Classes and Inheritance © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

Summary Instantiate an object Pass arguments when instantiating an object Write a class constructor Call a procedure in a separate class Chapter 11: Multiple Classes and Inheritance © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

Summary Code a base class and a subclass to incorporate inheritance Call procedures found in a base class and a subclass Write overridable and overrides procedures Create and write a comma-delimited text file Chapter 11: Multiple Classes and Inheritance

CHAPTER ELEVEN COMPLETE Multiple Classes and Inheritance