VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)

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

12-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
More about classes and objects Classes in Visual Basic.NET.
VB Classes ISYS 573. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Creating Custom Controls ISYS 512/812. Inheritance The process in which a new class can be based on an existing class, and will inherit that class’s interface.
Programming with Objects: Class Libraries and Reusable Code.
VB Classes - 2 ISYS 573. Creating an Array of Objects Dim emps(2) As emp Dim i As Integer For i = 0 To emps.GetUpperBound(0) emps(i) = New emp() Next.
Chapter 6 OOP: Creating Object-Oriented Programs Programming In Visual Basic.NET.
.NET Framework.NET Framework class libraries: A large set of classes that forms the basis for objects that can be used programmatically. –Programming in.
Advanced Object-Oriented Programming Features
VB Classes BICS546. Adding a Class to a Project Project/Add Class Class will be saved in a.CLS file Steps: –Adding properties Declare Public variables.
Inheritance and User-Defined Controls. Inheritance The process in which a new class can be based on an existing class, and will inherit that class’s interface.
VB.NET Classes ISYS 812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
VB Classes ISYS 573. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
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.
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.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
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.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Chapter 10: Writing Class Definitions Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 9: Getting Comfortable with Object- Oriented Programming.
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.
Java Classes ISYS 350. Introduction to Classes Two basic uses of class: – 1. A class is a way to organize functions (methods) to perform calculations.
C#/Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
CIS 338: Classes and Modules Dr. Ralph D. Westfall May, 2011.
Chapter Eleven Classes and Objects Programming with Microsoft Visual Basic th Edition.
Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
CSCI 3327 Visual Basic Chapter 3: Classes and Objects UTPA – Fall 2011.
Objects andVB Classes ISYS 350. What Is an Object? Objects are key to understanding object-oriented technology. There are many examples of real-world.
Chapter 6 OOP: Creating Object-Oriented Programs Programming In Visual Basic.NET.
1 Working with Objects. 2 Defining a Class in VB.NET A class is a user-defined data type You can declare it as part of a module, but usually in a separate.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Programming with Microsoft Visual Basic 2012 Chapter 11: Classes and Objects.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
C# Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the properties.
Object-Based Programming in VB.NET. Must Understand Following: Encapsulation Information hiding Abstract Data Type Class, Instance, Reference Variable.
Objects andVB Classes ISYS 350. What Is an Object? Objects are key to understanding object-oriented technology. There are many examples of real-world.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
C# Classes ISYS 512. Introduction to Classes A class is the blueprint for an object. –It describes a particular type of object. –It specifies the properties.
C# Classes ISYS 512. Introduction to Classes A class is the blueprint for an object. –It describes a particular type of object. –It specifies the properties.
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.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
These materials where developed by Martin Schray
Introduction to Object-oriented Programming
IS 350 Application Structure
Object-Oriented Programming: Classes and Objects
Inheritance and Polymorphism
Microsoft Visual Basic 2005: Reloaded Second Edition
Object-Oriented Programming: Classes and Objects
Object-Oriented Programming: Inheritance
Chapter 11 – Object-Oriented Programming
Programming paradigms
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Classes and Objects
Tonga Institute of Higher Education
CIS16 Application Development and Programming using Visual Basic.net
Classes & Objects A deeper Look Chapter 10 & 11
VB Classes ISYS 512.
Presentation transcript:

VB Classes ISYS 512/812

Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties) and behaviors (methods) of the object. For example, a Customer object is an abstract representation of a real customer. Encapsulation: –The combination of characteristics of an object along with its behavior. –Data hiding: Each object keeps its data and procedures hidden and exposes only those data elements and procedures that it wishes to allow outside world to see. The implementation of a class – in other words, what goes on inside the class – is separate from the class’s interface.

Inheritance: –The process in which a new class can be based on an existing class, and will inherit that class’s interface and behaviors. The original class is known as the base class, super class, or parent class. The inherited class is called a subclass, a derived class, or a child class. Polymorphism: The concept of using a single name for different behaviors. –Overloading: A class may have more than one methods with the same name but a different argument list (with a different number of parameters or with parameters of different data type), different parameter signature.

.Net Framework Class Library Structure Assembly: –Basic unit of deployment. –Implemented as Dynamic Link Library, DLL. –May contain many Namespace NameSpace: –Organize a group of related classes and namespaces. Class Object Browser

Referencing Assemblies and Classes Each project automatically references essential assemblies. –Project property/References –Or: Solution Explorer/Show All Files Add additional reference: –Project/Add Reference

Adding a Class to a Project Project/Add Class –*** MyClass is a VB keyword. Steps: –Adding properties Declare Public variables in the General Declaration section Property procedures: Set / Get –Adding methods –Adding events, exceptions

Anatomy of a Class Module Class Module Public Variables & Property Procedures Public Procedures & Functions Exposed Part Private Variables Private Procedures & Functions Hidden Part Private variables and procedures can be created for internal use.

Class Code Example Public Eid As String Public Ename As String Public salary As Double Public Function tax() As Double tax = salary * 0.1 End Function

Creating Property with Property Procedures Implementing a property with a public variable the property value cannot be validated by the class. We can create read-only, write-only, or write-once properties with property procedure. Steps: –Declaring a private class variable to hold the property value. –Writing a property procedure to provide the interface to the property value.

Private pvEid As String Private pvEname As String Private pvSalary As Double Public Property eid() As String Get eid = pvEid End Get Set(ByVal Value As String) pvEid = Value End Set End Property Public Property eName() As String Get eName = pvEname End Get Set(ByVal Value As String) pvEname = Value End Set End Property Public Property Salary() As Double Get Salary = pvSalary End Get Set(ByVal Value As Double) pvSalary = Value End Set End Property

Property Procedure Code Example Public Class Emp2 Public SSN As String Public Ename As String Public DateHired As Date Private hiddenJobCode As Long Public Property JobCode() Set(ByVal Value) If Value 4 Then hiddenJobCode = 1 Else hiddenJobCode = Value End If End Set Get JobCode = hiddenJobCode End Get End Property End Class

How the Property Procedure Works? When the program sets the property, the property procedure is called and the code between the Set and End Set statements is executed. The value assigned to the property is passed in the Value argument and is assigned to the hidden private variable. When the program reads the property, the property procedure is called and the code between the Get and End Get statements is executed.

Implementing a Read-Only Property Declare the property procedure as ReadOnly with only the Get block. Ex. Create a YearsEmployed property from the DateHired property: Public ReadOnly Property YearsEmployed() As Long Get YearsEmployed = Now.Year - DateHired.Year End Get End Property –Note: It is similar to a calculated field in database.

Implementing a Write-Only Property Declare the property procedure as WriteOnly with only the Set block. Ex. Create a PassWord property: Private hiddenPassword as String Public WriteOnly Property Password() As String Set(ByVal Value As String) hiddenPassword=Value End Set End Property

Method Overloading Using the Overloads Keyword Public Overloads Function tax() As Double tax = salary * 0.1 End Function Public Overloads Function tax(ByVal sal As Double) As Double tax = sal * 0.1 End Function

Constructors A constructor is a method that runs when a new instance of the class is created. In VB.Net the constructor method is always named Sub New.

Constructor Example Public Sub New() Me.eid = "" ename = "" salary = 0.0 End Sub Public Sub New(ByVal empId As String, ByVal empName As String, ByVal empSal As Double) eid = empId ename = empName salary = empSal End Sub Note: Cannot use Overloads with the New.

Difference between Assembly and Class A class defined in a project is available to that project only. Once a class is compiled in an assembly it can be used by any projects. To create an assembly: –Start a Class Library project

Steps to Create An Assembly Start a Class Library project Create classes –You can also use existing classes defined in other projects by Project/Add Existing Item Save project Select Build/Build to compile the code. –When the class library is compiled successfully, an assembly is created and stored in the project’s Bin/Release folder.

Using the Assembly Reference the assembly: Project/Add Reference and use the Browse button to select the assembly. Import the assembly. –Global import: Project property windows/References –Local import Using the Imports statement

Code Using Assembly Imports MyClassDemo Public Class Form1 Dim myButton As New Button Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim myCls As New DemoCls1 MessageBox.Show(myCls.myName) End Sub

Inheritance The process in which a new class can be based on an existing class, and will inherit that class’s interface and behaviors. The original class is known as the base class, super class, or parent class. The inherited class is called a subclass, a derived class, or a child class.

Employee Super Class with Three SubClasses All employee subtypes will have emp nbr, name, address, and date-hired Each employee subtype will also have its own attributes

Inheritance Example Public Class Emp Public Eid As String Public Ename As String Public salary As Double Public Function tax() As Double tax = salary * 0.1 End Function End Class Public Class secretary Inherits Emp Public WordsPerMinute As Integer End Class

Inherit Referenced Classes Imports MyClassDemo Public Class TestInherit Inherits DemoCls1 Public test As String End Class Public Class myTextBox Inherits System.Windows.Forms.TextBox Public myProperty As String End Class