Module 7: Object-Oriented Programming in Visual Basic .NET

Slides:



Advertisements
Similar presentations
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
Advertisements

Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
OOP / VB.NET (Chp4) DR. JOHN ABRAHAM UTPA Credit: Partial slides from startvbdotnet.com.
Chapter 11: Implementing Inheritance and Association Visual Basic.NET Programming: From Problem Analysis to Program Design.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
12-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
More about classes and objects Classes in Visual Basic.NET.
Object-Oriented PHP (1)
1 Inheritance & Interface. 2 Why Inheritance? Common properties? Methods to send congratulations to Employees and Customers Public Sub SendCongratulationsE(ByVal.
Advanced Object-Oriented Programming Features
VB Classes ISYS 573. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
ASP.NET Programming with C# and SQL Server First Edition
VB Classes ISYS 512. Adding a Class to a Project Project/Add Class –*** MyClass is a VB keyword. Steps: –Adding properties Declare Public variables in.
Object-Oriented Programming in Visual Basic.NET. Overview Defining Classes Creating and Destroying Objects Inheritance Interfaces Working with Classes.
Object-Oriented Programming: Inheritance Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Programming: Inheritance
To define a class in Visual Basic.NET, you can follow this general procedure: 1. Add a class to the project. 2. Provide an appropriate file name for.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Inheritance Chapter 14. What is inheritance?  The ability to create a class from another class, the “parent” class, extending the functionality and state.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Module 7: Essentials of Object-Oriented Programming.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 10: Writing Class Definitions Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 9: Getting Comfortable with Object- Oriented Programming.
Programming Pillars Introduction to Object- Oriented Programming.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
CSCI 3327 Visual Basic Chapter 3: Classes and Objects UTPA – Fall 2011.
Chapter 6 OOP: Creating Object-Oriented Programs Programming In Visual Basic.NET.
Session 02 and 03: C# OOP 1 OOP in C#: Classes and Objects in C#. Object-Oriented Design. UML Class Diagram. Object Interaction. FEN AK IT:
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Object-Oriented Programming Chapter Chapter
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Introduction to Object-Oriented Programming Lesson 2.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Chapter 2 11/18/2015 © by Pearson Education, Inc. All Rights Reserved. Lect9 GC 2011.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Object-Oriented Programming: Classes and Objects.
These materials where developed by Martin Schray
Modern Programming Tools And Techniques-I
Object-Oriented Programming: Classes and Objects
Inheritance and Polymorphism
Module 5: Common Type System
Microsoft Visual Basic 2005: Reloaded Second Edition
Table of Contents Class Objects.
Object-Oriented Programming: Classes and Objects
Object-Oriented Programming: Inheritance
Module 4: Implementing Object-Oriented Programming Techniques in C#
Object-Oriented Programming: Inheritance
Lecture 22 Inheritance Richard Gesick.
IS437: Fall 2004 Instructor: Dr. Boris Jukic
Inheritance Inheritance is a fundamental Object Oriented concept
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Classes and Objects
Object-Oriented Programming: Inheritance
CIS16 Application Development and Programming using Visual Basic.net
By Rajanikanth B OOP Concepts By Rajanikanth B
Object-Oriented Programming: Inheritance
Creating and Using Classes
Presentation transcript:

Module 7: Object-Oriented Programming in Visual Basic .NET

Overview Understanding Classes Working with Classes Debug and Deploy Write Code Access Data Use Visual Studio .NET Create Interface Understanding Classes Working with Classes Using Shared Members Inheritance, Polymorphism, and Namespaces

Multimedia: Introduction to Object-Oriented Concepts

Lesson: Understanding Classes abstraction class encapsulation object

What Is a Class? A class is a blueprint that describes an object and defines attributes and operations for the object Classes use abstraction to make available only the elements essential to defining the object Classes use encapsulation to enforce an abstraction What the user sees: What is encapsulated: //verify language //authenticate PIN //validate account bal //adjust account bal

What Is an Object? An object is an instance of a class Objects have the following qualities: Identity: Objects are distinguishable from one another Behavior: Objects can perform tasks State: Objects store information that can vary over time Class 123 245 12 Object Object

Lesson: Working with Classes How to Create a New Class How to Add Instance Data Members How to Add Methods How to Add Properties How to Create an Instance of a Class How to Use Constructors How to Use Destructors

How to Create a New Class Create a new class by using the Add Class command on the Project menu Example of new class named BankAccount: Public Class Class1 End Class Public Class BankAccount End Class

How to Add Instance Data Members Adding a data member named balance Public Class BankAccount Private balance As Double End Class Keyword Definition Public Accessible everywhere Private Accessible only within the type itself Protected Accessible only by classes which inherit from the class

How to Add Methods Adding a method named Deposit Public Class BankAccount Private balance As Double Public Sub Deposit(ByVal amount As Double) balance += amount End Sub End Class Overloaded methods: two or more methods with the same name but different signatures Example: MessageBox.Show

How to Add Properties Adding a property: Public Class BankAccount Private customerName As String Public Property Name( ) As String Get Return customerName End Get Set(ByVal Value As String) customerName = Value End Set End Property End Class

How to Create an Instance of a Class Using the New keyword to create an instance of the BankAccount class: Module Bank Sub Main Dim account As New BankAccount( ) account.Deposit(500.00) End Sub End Module

Practice: Creating a Class In this practice, you will create a BankAccount class with methods and properties

How to Use Constructors Executes code when object is instantiated Public Sub New( ) ' Perform simple initialization value = 1 End Sub Can overload, but does not use Overloads keyword Public Sub New(ByVal i As Integer) ' Overloaded without Overloads keyword ' Perform more complex initialization value = i End Sub

How to Use Destructors Used for resource cleanup Called by runtime before destroying object Important: Destruction might not happen immediately Protected Overrides Sub Finalize( ) ' Can close connections or other resources conn.Close End Sub

Lesson: Using Shared Members How to Use Shared Data Members How to Use Shared Methods

How to Use Shared Data Members Shared data members allow multiple class instances to refer to a single class-level variable Class SavingsAccount Public Shared InterestRate As Double Public Name As String, Balance As Double . . . End Class SavingsAccount.InterestRate = 0.03

How to Use Shared Methods Can be used without declaring a class instance Can only access shared data ' TestClass code Public Shared Function GetComputerName( ) As String ... End Function ' Client code MessageBox.Show(TestClass.GetComputerName( ))

Practice: Creating Shared Methods In this practice, you will: Create a class Add shared methods Use shared methods

Lesson: Inheritance, Polymorphism, and Namespaces structures and classes namespaces

What Is Inheritance? Inheritance specifies an “is-a-kind-of” relationship Multiple classes share the same attributes and operations, allowing efficient code reuse Examples: A customer “is a kind of” person An employee “is a kind of” person Base Class Person Customer Employee Derived Classes

How to Inherit from a Class A derived class inherits from a base class Properties, methods, data members, events, and event handlers can be inherited (dependent on scope) Keywords Inherits – inherits from a base class NotInheritable – cannot be inherited from MustInherit – instances of the class cannot be created; must be inherited from as a base class

What Is Polymorphism? The method name resides in the base class The method implementations reside in the derived classes BaseTax CalculateTax( ) CountyTax CityTax CalculateTax( ) CalculateTax( )

Comparing Classes to Structures Can define data members, properties, and methods Can define data members, properties, and methods Support constructors and member initialization No default constructor or member initialization Support Finalize method Do not support Finalize method Extensible by inheritance Do not support inheritance Reference type Value type

How to Organize Classes into Namespaces Namespaces are an organizational system Namespaces provide fully qualified names for classes Example: System.Windows.Forms.Button To import a namespace: At the project level, add a reference to the DLL that contains the namespace Use the Imports keyword

Review Understanding Classes Working with Classes Using Shared Members Debug and Deploy Write Code Access Data Use Visual Studio .NET Create Interface Understanding Classes Working with Classes Using Shared Members Inheritance, Polymorphism, and Namespaces

Lab 7.1: Creating a Derived Class Exercise 1: Creating a Derived Form Class