Добавил:
ivanov666
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Объектно-ориентированное программирование на языке Visual Basic 2008 в среде разработки Microsoft Visual Studio 2008 и .NET Framework. Часть 2. Учебно
.pdf
4
:
x , .
x .
x , .
x , .
x .
, .
. ,
( ),
, . , ,
.
. , . ,
Public Function frt() as Integer
…
End Function
()
frt()
,
, -
,
Public function frt (ByVal x As String) As Integer
frt(String).
,
,
.
:
1. (late binding).
2. (multiple interfaces).
3. (reflection).
4. .
51

. ,
Option Strict.
(early binding) , .
,
.
, . ,
. , , ,
(Dynamically Link Library-DLL) ,
.
, .
, LateBinding1
distance
Public Class LateBinding1
Public Function distance(ByVal x As Single, ByVal y As Single, ByVal z As Single) As Double
Return Math.Sqrt(x ^ 2 + y ^ 2 + z ^ 2)
End Function
End Class
, , Form1
LateBinding1 obj :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim obj As New LateBinding1
MsgBox(obj.distance(5, 5, 10))
End Sub
End Class
, . obj
LateBinding1, distance Double.
.
. -
52

Option Strict Option Strict Off ( ). , , . Visual Basic , ,
.
distance LateBinding1
Public Class LateBinding1
…
End Class
:
, Form1 :
Option Strict Off
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim obj As Object = New LateBinding1
MsgBox(obj.distance(5, 5, 10))
End Sub
End Class
(
), ,
.
Visual Basic IDE, ,
, , distance .
,
, -
.
- ,
.
53

, ..
, .
Form1 :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim obj As New LateBinding1
Showdistance(obj)
End Sub
Private Sub Showdistance(ByVal obj As Object)
MsgBox(obj.distance(5, 5, 10))
End Sub
Showdistance
: Integer, String ,
Object.
, ,
, distance,
.
, , IDE , ,
.
. Visual Basic
. ,
, , , Public.
() ,
Implements.
. . , , , , .. . , “I”,
IShared.
, Object, -
54

. ,
. Poly Polymorphism
Public Class Poly
Implements IShared
Public Function distance(ByVal x As Single, ByVal y As Single) As Single Implements _
IShared.SharedDistance
Return CSng(x + y)
End Function
End Class
Public Class Polymorphism
Implements IShared
Public Function distance(ByVal x As Single, ByVal y As Single) As Single Implements _
IShared.SharedDistance
Return CSng(Math.Sqrt(x ^ 2 + y ^ 2))
End Function
End Class
distance.
( -> )
Interface.vb
Module Interface
End Module
Public Interface IShared
Function SharedDistance(ByVal x As Single, ByVal y As Single) As Single
End Interface
IShared
SharedDistance distance Poly Polymorphism, , distance
SharedDistance.
, :
, .
.
Form1 Button :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim obj As New Poly
Showdistance(obj)
End Sub
55

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Dim obj As New Polymorphism
Showdistance(obj)
End Sub
Private Sub Showdistance(ByVal obj As Object)
Dim x, y As Single
x = CSng(InputBox(" x"))
y = CSng(InputBox(" y"))
MsgBox(obj.distance(x, y))
End Sub
End Class
Option Strict
Off. obj
Object IShared IDE
SharedDistance .
, IShared,
,
. :
,
, , ,
Private. ,
, .
,
,
.
56

4
,
.
, :
1. .
2. .
3. .
4. Implements.
5. .
6.
.
7. .
1. . 1.
2. .
3. .
2. , .
3. .
4. .
5. .
6. .
7. .
,
.
ComboBox
1
1 : ,
, , (
), .
.
2 : ,
, , (
),
.
.
57

3 :
()
( )
,
.
4 :
-
.
(.)
.
5 :
1 -
.
6
, -:
/
-
/
(
, ),
12
- "
-
( )
34
7
:
(, ),
,
5
58

8 , :
9 :
10 :
59

11
:
12
:
13
:
60
Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]
