Shane Partridge
Visual Basic 2013
The Code
Public Class MyClass1
'## Public Class MyClass1 ##
'## Encapsulation ##
'## Encapsulation refers to the creation of self-contained modules that bind processing functions to the data. ##
'## These user-defined data types are called classes. Each class contains data as well as a set of methods ##
'## which manipulate the data.The data components of a class are called instance variables and one instance of a ##
'## class is an object. For example, in a library system, a class could be a member, and John and Sharon ##
'## could be two instances (two objects) of the library class. ##
'## Inheritance ##
'## Classes are created according to hierarchies, and inheritance allows the structure and methods ##
'## in one class to be passed down the hierarchy.That means less programming is required when adding ##
'## functions to complex systems. If a step is added at the bottom of a hierarchy, then only the ##
'## processing and data associated with that unique step needs to be added. ##
'## Everything else about that step is inherited. ##
'## Polymorphism ##
'## -oriented programming allows procedures about objects to be created whose exact type ##
'## is not known until runtime. For example, a screen cursor may change its shape from an ##
'## arrow to a line depending on the program mode. The routine to move the cursor on the screen ##
'## in response to mouse movement would be written for “cursor,” and polymorphism allows that cursor ##
'## to take on whatever shape is required at runtime.It also allows new shapes to be easily ##
'## integrated.Visual Basic 2013 allows users to write programs that break down into modules. ##
'## These modules represent the real-world objects and are knows as classes or types.##
'## An object can be created out of a class and it is known as an instance of the class. ##
'## A class can also comprise subclass. For example, the apple tree is a subclass of the ##
'## plant class and the apple in your backyard is an instance of the apple tree class. ##
'## Another example is student class is a subclass of the human class while your son John ##
'## is an instance of the student class. ##
'## Hypotenuse Encapsulation ##
'## Hypotenuse Formula ##
'## Public Class MyClass1 - Hypotenuse Functional Inheritance ##
'## (Public Class MyClass1) to (Form1.vb Public Class Form1) ##
Public Function Hypotenuse(ByVal Side1 As Integer, ByVal Side2 As Integer)
Hypotenuse = Format((Side1 ^ 2) + (Side2 ^ 2))
End Function
End Class
'## Public Class Form1 Encapsulation & Inheritance of Public Class Myclass1 ##
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim MyObject As Object
Dim Side1, Side2 As Integer
Dim SquareRoot as interger
SquareRoot = 0.5
'## MyObject Inheritance ##
'## Calculate Hypotenuse ##
MyObject = New MyClass1()
Side1 = InputBox("Enter Side1 Length")
Side2 = InputBox("Enter Side2 Length")
MessageBox.Show(MyObject.Hypotenuse(Side1, Side2) ^ SquareRoot)
End Sub
End Class