Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.

Slides:



Advertisements
Similar presentations
Chapter 12 OOP: Creating Object- Oriented Programs Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Advertisements

CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
12-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
More about classes and objects Classes in Visual Basic.NET.
Chapter 6 OOP: Creating Object-Oriented Programs Programming In Visual Basic.NET.
Advanced Object-Oriented Programming Features
ASP.NET Programming with C# and SQL Server First Edition
Chapter 13: Object-Oriented Programming
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Object-Oriented Programming in Visual Basic.NET. Overview Defining Classes Creating and Destroying Objects Inheritance Interfaces Working with Classes.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Object-Oriented Programming: Inheritance
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
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.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
A First Program Using C#
Chapter 12: Adding Functionality to Your Classes.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2005: Reloaded Second Edition
Module 7: Object-Oriented Programming in Visual Basic .NET
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Chapter 8: Writing Graphical User Interfaces
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Chapter 6 OOP: Creating Object-Oriented Programs Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
Chapter Eleven Classes and Objects Programming with Microsoft Visual Basic th Edition.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 6 OOP: Creating Object-Oriented Programs Programming In Visual Basic.NET.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Programming with Microsoft Visual Basic 2012 Chapter 11: Classes and Objects.
1.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Introduction to Object-Oriented Programming Lesson 2.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Object-Oriented Programming: Inheritance and Polymorphism.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Object-Oriented Programming: Classes and Objects.
Object-Oriented Programming: Classes and Objects
Introduction to Visual Basic 2008 Programming
Multiple Classes and Inheritance
Microsoft Visual Basic 2005: Reloaded Second Edition
Object-Oriented Programming: Classes and Objects
One class is an extension of another.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Lecture Set 11 Creating and Using Classes
Java Programming, Second Edition
Object-Oriented Programming: Classes and Objects
Object-Oriented Programming: Inheritance and Polymorphism
Presentation transcript:

Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance

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

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 ]

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

11 Class Vocabulary ►Class [ blueprint for an object ] encapsulation data hiding code reuse stability complexity multiple programmers ►Class components attributes behaviors properties state Chapter 11: Multiple Classes and Inheritance5

11 Class Vocabulary ►Object [ instance of a class ] variables [ instance / shared ] method types ►sub procedures ►function procedures method purpose ►accessor (query) method ►mutator method ►utility method constructor(s) destructor ►Object-Oriented Design Tools inheritance polymorphism overloading overriding abstract classes abstract methods class variables class methods Chapter 11: Multiple Classes and Inheritance6

11 Class Vocabulary ►Object instantiation reference variable class creation expression [ new ] object. member or class. member null reference ►Class keywords Class Friend Get Implements Inherits Interface Me MustInherit MustOverride MyBase New NotInheritable NotOverridable Chapter 11: Multiple Classes and Inheritance7 Object Overridable Overrides Private Property Protected Public ReadOnly Set Shadows WriteOnly

11 Chapter 11: Multiple Classes and Inheritance8 Chapter Project

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

11 Chapter 11: Multiple Classes and Inheritance10 User Interface and the TabIndex Property

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

11 Chapter 11: Multiple Classes and Inheritance12 Editing Input Data MaskedTextBox MaskFull property

11 Chapter 11: Multiple Classes and Inheritance13 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 Chapter 11: Multiple Classes and Inheritance14 Program Structure Using Classes ►presentation tier: [ GUI ] contains the classes that display information for the user and accept user input ►business tier: [ Problem Domain / Business Logic ] contains the logic and calculations that must occur in order to fulfill the requirements of the program ►persistence tier: [ Data Access ] sometimes called the data access tier, contains the code required to read and write data from permanent storage

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

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

11 Chapter 11: Multiple Classes and Inheritance17 Creating a Class

11 Chapter 11: Multiple Classes and Inheritance18 Instantiating a Class [ New ] 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

11 Chapter 11: Multiple Classes and Inheritance19 Constructors ►When a class is instantiated, an object is created. Generally this is done using the New keyword. ►Once the object is created, a special procedure in the instantiated class called a constructor is executed ►The constructor prepares the object for use in the program by initializing class-level variables. ►Every class has a constructor. ►If no constructor was created by the programmer, VisualBasic.NET provides a “default” constructor that doesn’t do anything…

11 Chapter 11: Multiple Classes and Inheritance20 Constructors ►VisualBasic permits “overloaded” constructors just as it permits overloaded function and sub procedures ►Below is a “default” aka “no-argument” constructor

11 Chapter 11: Multiple Classes and Inheritance21 Passing Arguments to a Constructor ►Often when instantiating an object, data must be passed to the constructor 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

11 Chapter 11: Multiple Classes and Inheritance22 Passing Arguments to a Constructor when Instantiating an Object

11 Chapter 11: Multiple Classes and Inheritance23 Calling a Procedure in a Different Object ►Most of the time, separate objects in a program contain procedures [methods] that must be executed

11 Chapter 11: Multiple Classes and Inheritance24 Inheritance ►Inheritance allows one class to inherit attributes and behaviors from another class ►Attributes: variables ►Behaviors: methods Subclass ResidenceHall

11 Chapter 11: Multiple Classes and Inheritance25 Inheritance Permissible Access Modifiers: Public, Private, Protected, Friend

11 Chapter 11: Multiple Classes and Inheritance26 Inheritance [ General ----> Specific ] The Inherits keyword precedes the name of the base class for a subclass. Remember, you inherit variables and methods.

11 Chapter 11: Multiple Classes and Inheritance27 Constructors BASE CLASS CONSTRUCTOR [ Student ]

11 Chapter 11: Multiple Classes and Inheritance28 Constructors SUBCLASS CONSTRUCTOR [ OnCampusStudent ] MyBase is a referece to the base class of the subclass. This is similar to the reference Me by which a class [object] refers to itself.

11 Chapter 11: Multiple Classes and Inheritance29 Inheritance and Procedures [Methods] ►When using inheritance, the subclass can use the procedures and variables inherited from the base class [ must be public/protected ] ►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:

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

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

11 Chapter 11: Multiple Classes and Inheritance32 Creating an Overridable Method Calling base class version in subclass

11 Chapter 11: Multiple Classes and Inheritance33 Creating an Overrides Method [ subclass ] Overrode the base class overridable function

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

11 Chapter 11: Multiple Classes and Inheritance35 Persistence Classes

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

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

11 Chapter 11: Multiple Classes and Inheritance38 Program Design

11 Chapter 11: Multiple Classes and Inheritance39 Program Design

11 Chapter 11: Multiple Classes and Inheritance40 Program Design

11 Chapter 11: Multiple Classes and Inheritance41 Event Planning Document

11 Chapter 11: Multiple Classes and Inheritance42 Event Planning Document

11 Chapter 11: Multiple Classes and Inheritance43 Event Planning Document

11 Chapter 11: Multiple Classes and Inheritance44 Event Planning Document

11 Chapter 11: Multiple Classes and Inheritance45 Event Planning Document

Microsoft Visual Basic 2008 CHAPTER 11 COMPLETE Multiple Classes and Inheritance