SlideShare a Scribd company logo
1
Lesson 8 — Classes and Objects
Microsoft Visual
Basic .NET, Introduction
to Programming
2
Objectives
 Use the Object Browser to explore classes
and objects.
 Design and create classes.
 Use class modules to declare and use
objects.
 Add methods, events, and properties to
classes.
3
Vocabulary
 Business rules
 ByVal
 Data encapsulation
 data hiding
 Inheritance
 Object-oriented
programming (OOP)
 Operator overloading
 Platforms
 Polymorphism
 Reusable code
 StrConv()
4
Maximum Effect with Minimum Effort
 Every programmer wants to be more productive.
"Maximum effect with minimum effort" is an old
saying endorsed by every programmer.
 Programmers want a programming environment that
makes it easy to write code. Programmers want their
programs to work on several different platforms.
 Working on different platforms means writing
programs that work on different combinations of
hardware and operating systems.
 Programmers want to write reusable code, which is
code you can use in more than one program.
5
Object-Oriented Programming (OOP )
The foundation of OOP is data — data and
the operations performed on the data.
An object contains both data and the
operations that can be performed on the
data. For example, a list box is an object. It
contains the data in its Items collection and
the operations that can be performed on the
data. The operations are called methods.
6
Data Encapsulation
Data encapsulation means hiding information from the
user and the programmer. How does a list box store
information in memory? What code does it use to sort its
contents?
In OOP, these questions are not concerns of the
programmer. To communicate with an object, a
programmer writes code that sends messages to the
objects. The messages instruct the objects what
operations to perform on the data they contain.
Communication is restricted to the messages, making the
internal working of the object hidden from the user and the
programmer.
7
Data Hiding
Data hiding allows a programmer to worry
about problem solving rather than about
writing code to handle the details of storing
and operating on data. Objects take care of
the details for you.
8
Inheritance
When you create a new class based on a simpler
existing class, the new class inherits all the
properties of the original class, a principle called
inheritance.
In this new class, you can replace or extend the
properties of the original class. The new class may
add new methods and properties to the
functionality of the old class while retaining all the
original class's functionality.
9
Polymorphism
Polymorphism is redefining methods,
properties, and operations to behave
differently with different objects.
10
Operator Overloading
The lowly plus symbol (+) has many functions:
It adds integers, decimals, and doubles, and it
joins strings together. Each operation calls for
different code to execute the operation within
the context in which it occurs.
Operator overloading is the term that refers to
the ability of the existing operators to have
more than one function depending on the
context.
11
The Object Browser
The Object Browser lets you look at classes
and the properties of the objects created
from the classes.
12
The Object Browser
13
The Find Symbol Dialog Box
14
Creating a Class
The simplest classes are a lot like structures. You use
structures to create new data types. You can use
classes the same way, but more often, you use classes
to create objects of user-defined data types along with
the operations you need to process, store, or display the
data.
The simplest way to define a property in a class is a
simple variable declaration. A Public variable
declaration, like Public Name As String, in the class
definition provides a Name property of type String for
any object created with that class definition.
15
Property Procedure
Property Name As DataType
Get
Code called when the property is read
End Get
Set
Code called when the data are written to the
property
End Set
End Property
16
Classes
Defining public variables in a Class module is
equivalent to adding properties to the objects
created with the class. Adding Public
procedures to a Class module is equivalent
to adding methods to the objects created with
the class.
17
Note
Remember, a method is an action that an
object can perform. For example, the list box
object can execute the Clear method on its
Items collection to clear its contents, or it can
execute the Add method to add a new entry
to the Items collection of the list box.
18
Computer Ethics
Building business rules into class definitions
makes it easier to enforce those rules. If
every programmer in the shop is required to
use the same unmodified class definitions, all
are compelled to use the same business
rules.
19
Adding an Event
 First, you must declare an event in the Class
definition.
 Then you must write code in the Class
definition to raise the event.
 Lastly, in the calling program, you must
declare object variables using the
WithEvents keyword and write an event
procedure to respond to the event when it
occurs.
20
ByVal Keyword
The ByVal keyword in a parameter list sends a
parameter's value to the function. Because the
function does not know the parameter's address, it
cannot change the actual value of the parameter.
The value of the parameter can be used in the
function. The program can change the value of the
variable that represents the parameter, but it cannot
change the actual value of the parameter as defined
in the calling program. The ByRef keyword passes
the parameter by address. This means the program
can make permanent changes to the parameter sent
to the procedure.
21
Summary
 Programmers want better programming environments, cross-
platform applications, and reusable code modules.
 Visual Basic is the root language of many Microsoft products,
including Microsoft Office.
 Object-oriented programming (OOP) focuses on creating
objects that include data and the operations performed on the
data.
 Data encapsulation, part of the OOP paradigm, is the ability of
an object to hide data and methods from the user or even the
programmer. This protects data from accidental alteration.
 Inheritance is the ability of an OOP class to inherit properties
and methods from other classes.
22
Summary
 Polymorphism is the ability to define multiple uses for the same
operators and methods.
 You create objects from the templates provided by classes.
 The Object Browser lets the programmer look at classes and
the properties of the object created from the classes.
 You add class definitions to a project by selecting Project | Add
Class from the menu bar.
 Public variables declared in the Declarations section of the
class definition become properties of objects created with the
new class.
23
Summary
 Private variables declared in the Declarations section of a class
definition are available within the definition but cannot be
accessed outside the definition.
 The program uses Property procedures to gather and provide
properties to objects. The program also uses the procedures to
modify or process the properties.
 The StrConv( ) function can be used to convert an input string
to a string where the first character is capitalized and the other
characters are lowercase.
 A new object created from a class is an instance, or an
instantiation, of the class.
 You can save objects in text files by saving each part of the
object as text in the file.
24
Summary
 Public procedures and functions recorded in a class definition
become the methods of the objects created with the class.
 A business rule is a rule of the workplace written into the code
of a program. When put into class definitions, business rules
are easy to manage and implement.
 The SelectedIndex property of a list box contains the index
value of the item currently selected in the list.
 To add an event to a class module, first declare the event in the
Declarations section of the class definition, then write code to
raise the event. The code initiates the event when some
condition is satisfied (or not satisfied) in the class definition.
25
Summary
 To use event definitions in a class definition, use the
WithEvents keyword in an application to declare the objects of
that class.
 The ByVal keyword in a parameter list sends a parameter's
value to a function, not the parameter's address.
 The program uses the RaiseEvent statement in a Class
definition to fire an event procedure.
 Class definitions are at their best when used to hide the details
of program operations from a programmer and provide the
programmer with an easy-to-use interface to the data in the
objects created from the class definition.

More Related Content

Similar to Classes and objects object oriented programming (20)

Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
SyedUmairAli9
 
Chapter1
Chapter1Chapter1
Chapter1
jammiashok123
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
Amresh Raj
 
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
NicheTech Com. Solutions Pvt. Ltd.
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
vamshimahi
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
cesarmendez78
 
C++ basic intro on c++ programming language ppt
C++ basic intro on c++ programming language pptC++ basic intro on c++ programming language ppt
C++ basic intro on c++ programming language ppt
PavithraD65
 
Object Oriented Programming (Advanced )
Object Oriented Programming   (Advanced )Object Oriented Programming   (Advanced )
Object Oriented Programming (Advanced )
ayesha420248
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
Shipra Swati
 
Java chapter 3
Java   chapter 3Java   chapter 3
Java chapter 3
Mukesh Tekwani
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
Sangharsh agarwal
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
JITTAYASHWANTHREDDY
 
Unit i
Unit iUnit i
Unit i
Saravanan Pitchai
 
B vb script11
B vb script11B vb script11
B vb script11
oakhrd
 
Software_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptxSoftware_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptx
ArifaMehreen1
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
Programming with Objective-C
Programming with Objective-CProgramming with Objective-C
Programming with Objective-C
Nagendra Ram
 
1 intro
1 intro1 intro
1 intro
abha48
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
SyedUmairAli9
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
Amresh Raj
 
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
NicheTech Com. Solutions Pvt. Ltd.
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
vamshimahi
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
cesarmendez78
 
C++ basic intro on c++ programming language ppt
C++ basic intro on c++ programming language pptC++ basic intro on c++ programming language ppt
C++ basic intro on c++ programming language ppt
PavithraD65
 
Object Oriented Programming (Advanced )
Object Oriented Programming   (Advanced )Object Oriented Programming   (Advanced )
Object Oriented Programming (Advanced )
ayesha420248
 
B vb script11
B vb script11B vb script11
B vb script11
oakhrd
 
Software_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptxSoftware_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptx
ArifaMehreen1
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
Programming with Objective-C
Programming with Objective-CProgramming with Objective-C
Programming with Objective-C
Nagendra Ram
 
1 intro
1 intro1 intro
1 intro
abha48
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 

More from areebakanwal12 (12)

Streaming and input output mOOPlec9.pptx
Streaming and input output mOOPlec9.pptxStreaming and input output mOOPlec9.pptx
Streaming and input output mOOPlec9.pptx
areebakanwal12
 
SE lect2_2.pptxv model design software models
SE lect2_2.pptxv model design software modelsSE lect2_2.pptxv model design software models
SE lect2_2.pptxv model design software models
areebakanwal12
 
ENERGEYCRISES ARE THE LARGEST SINGLE DRAIN ON PAKISTAN ECONOMY.pptx
ENERGEYCRISES ARE THE LARGEST SINGLE DRAIN ON PAKISTAN ECONOMY.pptxENERGEYCRISES ARE THE LARGEST SINGLE DRAIN ON PAKISTAN ECONOMY.pptx
ENERGEYCRISES ARE THE LARGEST SINGLE DRAIN ON PAKISTAN ECONOMY.pptx
areebakanwal12
 
02-7 Habits for successLecture review.pptx
02-7 Habits for successLecture review.pptx02-7 Habits for successLecture review.pptx
02-7 Habits for successLecture review.pptx
areebakanwal12
 
presentationeerrrrrrrr-190220050301.pptx
presentationeerrrrrrrr-190220050301.pptxpresentationeerrrrrrrr-190220050301.pptx
presentationeerrrrrrrr-190220050301.pptx
areebakanwal12
 
Parallel computing and programming of parallel environment
Parallel computing and programming of parallel environmentParallel computing and programming of parallel environment
Parallel computing and programming of parallel environment
areebakanwal12
 
Web Engineering Process Models- An introduction.pptx
Web Engineering Process Models- An introduction.pptxWeb Engineering Process Models- An introduction.pptx
Web Engineering Process Models- An introduction.pptx
areebakanwal12
 
professional ethics about ethical values in workplace
professional ethics about ethical values in workplaceprofessional ethics about ethical values in workplace
professional ethics about ethical values in workplace
areebakanwal12
 
turing machine theory and making process.pptx
turing machine theory and making process.pptxturing machine theory and making process.pptx
turing machine theory and making process.pptx
areebakanwal12
 
SE_Requirement Engineering Process Models
SE_Requirement Engineering Process ModelsSE_Requirement Engineering Process Models
SE_Requirement Engineering Process Models
areebakanwal12
 
Data encapsulation and information hiding
Data encapsulation and information hidingData encapsulation and information hiding
Data encapsulation and information hiding
areebakanwal12
 
Classes and objects constructor and destructor
Classes and objects constructor and destructorClasses and objects constructor and destructor
Classes and objects constructor and destructor
areebakanwal12
 
Streaming and input output mOOPlec9.pptx
Streaming and input output mOOPlec9.pptxStreaming and input output mOOPlec9.pptx
Streaming and input output mOOPlec9.pptx
areebakanwal12
 
SE lect2_2.pptxv model design software models
SE lect2_2.pptxv model design software modelsSE lect2_2.pptxv model design software models
SE lect2_2.pptxv model design software models
areebakanwal12
 
ENERGEYCRISES ARE THE LARGEST SINGLE DRAIN ON PAKISTAN ECONOMY.pptx
ENERGEYCRISES ARE THE LARGEST SINGLE DRAIN ON PAKISTAN ECONOMY.pptxENERGEYCRISES ARE THE LARGEST SINGLE DRAIN ON PAKISTAN ECONOMY.pptx
ENERGEYCRISES ARE THE LARGEST SINGLE DRAIN ON PAKISTAN ECONOMY.pptx
areebakanwal12
 
02-7 Habits for successLecture review.pptx
02-7 Habits for successLecture review.pptx02-7 Habits for successLecture review.pptx
02-7 Habits for successLecture review.pptx
areebakanwal12
 
presentationeerrrrrrrr-190220050301.pptx
presentationeerrrrrrrr-190220050301.pptxpresentationeerrrrrrrr-190220050301.pptx
presentationeerrrrrrrr-190220050301.pptx
areebakanwal12
 
Parallel computing and programming of parallel environment
Parallel computing and programming of parallel environmentParallel computing and programming of parallel environment
Parallel computing and programming of parallel environment
areebakanwal12
 
Web Engineering Process Models- An introduction.pptx
Web Engineering Process Models- An introduction.pptxWeb Engineering Process Models- An introduction.pptx
Web Engineering Process Models- An introduction.pptx
areebakanwal12
 
professional ethics about ethical values in workplace
professional ethics about ethical values in workplaceprofessional ethics about ethical values in workplace
professional ethics about ethical values in workplace
areebakanwal12
 
turing machine theory and making process.pptx
turing machine theory and making process.pptxturing machine theory and making process.pptx
turing machine theory and making process.pptx
areebakanwal12
 
SE_Requirement Engineering Process Models
SE_Requirement Engineering Process ModelsSE_Requirement Engineering Process Models
SE_Requirement Engineering Process Models
areebakanwal12
 
Data encapsulation and information hiding
Data encapsulation and information hidingData encapsulation and information hiding
Data encapsulation and information hiding
areebakanwal12
 
Classes and objects constructor and destructor
Classes and objects constructor and destructorClasses and objects constructor and destructor
Classes and objects constructor and destructor
areebakanwal12
 
Ad

Recently uploaded (20)

Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Bonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdfBonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdf
Herond Labs
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 WebinarPorting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Bonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdfBonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdf
Herond Labs
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 WebinarPorting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Ad

Classes and objects object oriented programming

  • 1. 1 Lesson 8 — Classes and Objects Microsoft Visual Basic .NET, Introduction to Programming
  • 2. 2 Objectives  Use the Object Browser to explore classes and objects.  Design and create classes.  Use class modules to declare and use objects.  Add methods, events, and properties to classes.
  • 3. 3 Vocabulary  Business rules  ByVal  Data encapsulation  data hiding  Inheritance  Object-oriented programming (OOP)  Operator overloading  Platforms  Polymorphism  Reusable code  StrConv()
  • 4. 4 Maximum Effect with Minimum Effort  Every programmer wants to be more productive. "Maximum effect with minimum effort" is an old saying endorsed by every programmer.  Programmers want a programming environment that makes it easy to write code. Programmers want their programs to work on several different platforms.  Working on different platforms means writing programs that work on different combinations of hardware and operating systems.  Programmers want to write reusable code, which is code you can use in more than one program.
  • 5. 5 Object-Oriented Programming (OOP ) The foundation of OOP is data — data and the operations performed on the data. An object contains both data and the operations that can be performed on the data. For example, a list box is an object. It contains the data in its Items collection and the operations that can be performed on the data. The operations are called methods.
  • 6. 6 Data Encapsulation Data encapsulation means hiding information from the user and the programmer. How does a list box store information in memory? What code does it use to sort its contents? In OOP, these questions are not concerns of the programmer. To communicate with an object, a programmer writes code that sends messages to the objects. The messages instruct the objects what operations to perform on the data they contain. Communication is restricted to the messages, making the internal working of the object hidden from the user and the programmer.
  • 7. 7 Data Hiding Data hiding allows a programmer to worry about problem solving rather than about writing code to handle the details of storing and operating on data. Objects take care of the details for you.
  • 8. 8 Inheritance When you create a new class based on a simpler existing class, the new class inherits all the properties of the original class, a principle called inheritance. In this new class, you can replace or extend the properties of the original class. The new class may add new methods and properties to the functionality of the old class while retaining all the original class's functionality.
  • 9. 9 Polymorphism Polymorphism is redefining methods, properties, and operations to behave differently with different objects.
  • 10. 10 Operator Overloading The lowly plus symbol (+) has many functions: It adds integers, decimals, and doubles, and it joins strings together. Each operation calls for different code to execute the operation within the context in which it occurs. Operator overloading is the term that refers to the ability of the existing operators to have more than one function depending on the context.
  • 11. 11 The Object Browser The Object Browser lets you look at classes and the properties of the objects created from the classes.
  • 13. 13 The Find Symbol Dialog Box
  • 14. 14 Creating a Class The simplest classes are a lot like structures. You use structures to create new data types. You can use classes the same way, but more often, you use classes to create objects of user-defined data types along with the operations you need to process, store, or display the data. The simplest way to define a property in a class is a simple variable declaration. A Public variable declaration, like Public Name As String, in the class definition provides a Name property of type String for any object created with that class definition.
  • 15. 15 Property Procedure Property Name As DataType Get Code called when the property is read End Get Set Code called when the data are written to the property End Set End Property
  • 16. 16 Classes Defining public variables in a Class module is equivalent to adding properties to the objects created with the class. Adding Public procedures to a Class module is equivalent to adding methods to the objects created with the class.
  • 17. 17 Note Remember, a method is an action that an object can perform. For example, the list box object can execute the Clear method on its Items collection to clear its contents, or it can execute the Add method to add a new entry to the Items collection of the list box.
  • 18. 18 Computer Ethics Building business rules into class definitions makes it easier to enforce those rules. If every programmer in the shop is required to use the same unmodified class definitions, all are compelled to use the same business rules.
  • 19. 19 Adding an Event  First, you must declare an event in the Class definition.  Then you must write code in the Class definition to raise the event.  Lastly, in the calling program, you must declare object variables using the WithEvents keyword and write an event procedure to respond to the event when it occurs.
  • 20. 20 ByVal Keyword The ByVal keyword in a parameter list sends a parameter's value to the function. Because the function does not know the parameter's address, it cannot change the actual value of the parameter. The value of the parameter can be used in the function. The program can change the value of the variable that represents the parameter, but it cannot change the actual value of the parameter as defined in the calling program. The ByRef keyword passes the parameter by address. This means the program can make permanent changes to the parameter sent to the procedure.
  • 21. 21 Summary  Programmers want better programming environments, cross- platform applications, and reusable code modules.  Visual Basic is the root language of many Microsoft products, including Microsoft Office.  Object-oriented programming (OOP) focuses on creating objects that include data and the operations performed on the data.  Data encapsulation, part of the OOP paradigm, is the ability of an object to hide data and methods from the user or even the programmer. This protects data from accidental alteration.  Inheritance is the ability of an OOP class to inherit properties and methods from other classes.
  • 22. 22 Summary  Polymorphism is the ability to define multiple uses for the same operators and methods.  You create objects from the templates provided by classes.  The Object Browser lets the programmer look at classes and the properties of the object created from the classes.  You add class definitions to a project by selecting Project | Add Class from the menu bar.  Public variables declared in the Declarations section of the class definition become properties of objects created with the new class.
  • 23. 23 Summary  Private variables declared in the Declarations section of a class definition are available within the definition but cannot be accessed outside the definition.  The program uses Property procedures to gather and provide properties to objects. The program also uses the procedures to modify or process the properties.  The StrConv( ) function can be used to convert an input string to a string where the first character is capitalized and the other characters are lowercase.  A new object created from a class is an instance, or an instantiation, of the class.  You can save objects in text files by saving each part of the object as text in the file.
  • 24. 24 Summary  Public procedures and functions recorded in a class definition become the methods of the objects created with the class.  A business rule is a rule of the workplace written into the code of a program. When put into class definitions, business rules are easy to manage and implement.  The SelectedIndex property of a list box contains the index value of the item currently selected in the list.  To add an event to a class module, first declare the event in the Declarations section of the class definition, then write code to raise the event. The code initiates the event when some condition is satisfied (or not satisfied) in the class definition.
  • 25. 25 Summary  To use event definitions in a class definition, use the WithEvents keyword in an application to declare the objects of that class.  The ByVal keyword in a parameter list sends a parameter's value to a function, not the parameter's address.  The program uses the RaiseEvent statement in a Class definition to fire an event procedure.  Class definitions are at their best when used to hide the details of program operations from a programmer and provide the programmer with an easy-to-use interface to the data in the objects created from the class definition.

Editor's Notes