Oop
Oop
&
VB.NET
OOP
• Object Oriented Programming
• Deals with objects that have attributes and behaviors.
• Classes
• Is an prototype to create object
• Objects
• Is an entity that has a state and exhibits behavior
• Data Encapsulation
• Process of storing all the data members and method in a single unit
called class.
• Data Abstraction
• Process of hiding the complex details of a system and providing
only the essential features.
• Inheritance
• Inherits the members that have been already created along with
the existing members.
• Polymorphism
• ability to exist is more than one form.
Benefits
• Reusability
• Using the features of inheritance members and methods in a class can be used effectively
by the objects of an inherited class.
• Flexibility to change
• If the method has been changed that will be applicable to all the classes that inherits that
class.
• Data security
• Depending upon the security and accessibility data members can be declared private or
public
Creating Classes
• Class
• Entities that share common attributes and behaviors.
Syntax to create class
Class <<classname>>
End Class
• Visual Inheritance
• Create a normal window application
• Generate the code
• To inherit ProjectAdd Inherit form
Open
Inheritance
Inheritance
Polymorphisim
• Structures
• Stores multiple values in the form of a record that can be of same type or of
different types.
• Enumeration
• Named constants
• Values with unique names so that the values can be identified globally.
Structures
• Creating Structures
• Declare a Structure.
• Store the information inside it.
Syntax
Structure <<structurename>>
‘Declaration of variables
End Structure
Example
Structure Employee
Public emp_fname as String
Public emp_lname as String
Public emp_age as Double
Public emp_dob as Date
End Structure
Structures
• Accessing data
• Create objects of the structure
• Using the objects the members can be accessed by the dot
notation.
Example
Dim empobj as Employee
empobj.emp_fname=“Kala”
empobj.emp_lname=“Mala”
empobj.emp_age=10
Structure Vs Classes
Class Structure
Inheritable Not inheritable
Have constructors with or without Have constructors only with
parameters parameters
Have reference-type variables Have value type variables
Members can be initialized within Members cannot be initialized
the class declaration within the Structure declaration.
Enumeration
• Creating Enumeration
• Has an underlying base datatype which must be
numeric
• Every enumeration contains
• Name
• Underlying data type (must be Integer)
• Set of data
Syntax
<<accessmodifier>> Enum <<enumname>>
As <<numeridatatype>> <<varnam>> = [value]
End Enum
Example
Public Enum shapes
Square
rectangle
Circle
End Enum
Enumeration
• Assigning Values
• Assigning values to the variable is possible
Example
Public Enum shapes
Square =5
rectangle=10
Circle=15
End Enum
End Select
End Function
Referenced Data types
• Stores a pointer to another memory
location that contains data.
• Two kinds exist
• Arrays
• Classes
• Arrays
• Store multiple values of same data type using a single
name
• Values are accessed using indexes.
• Index starts from zero
• Types of Array
• Single-dimensional array
• Multi-dimensional array
• Array of array or jagged array
• Dynamic array
Single dimensional Array
• Provide name, size and data type
• Declared using Dim command.
Syntax
Dim <<arrayname>>(<<maxsize>>) as <<datatype>>
Example
Dim arr(15) as Integer
• Indexes starts from 0
• arr can store 16 values of Integer data types
Single dimensional Array
• Initializing the array
• Locate the array element using its indexes.
Example
arr(0)=1
arr(1)=10
arr(2)=20
Dim score(3 to 5 ) as Integer
• Indexes number has been explicitly
declared
• Accessing Array elements
• Done by indexes
Example
if arr(0)>0 then
Console.WriteLine(“Present”)
End if
Multi Dimensional Array
• An array having a rank more than one is called as
multi-dimensional array
• Same as table having n number of columns.
• Each column represents the entity.
• Each row represents the attribute
• Two-dimensional is the simplest form
• Has rows and columns
Multi Dimensional Array
• Creating a multi-dimensional array
• Specify the number of rows and columns
Example
Dim arr(4,5) as Integer
• Initialization
• Done by indexes
• Needs both indexes to locate
Example
arr(1,3) =20
• Accessing Elements
• Same as initialization
Example
if arr(1,3)>0 then
Console.WriteLine(“Present”)
End if
Jagged Array
• Declaration
• Multiple sets of paranthesis
Example
to declare arr(),arr1(a,b),arr2(c,d,e)
Dim arr()() As String=(New String() {“arr1”},
New String(){“a”,”b”}, New String(){“c”,”d”,”e”}}
• Initialization
• Specify the location using the indexes
Example
arr(2,2)=34
Dynamic Arrays
• At the time of creation the number of
elements are not known the size of the
array can be specified later
• This is called as Dynamic array
• Declare the array without specifying the
size
Example
Dim arr() As Integer