2002-03-25
| Table of Contents: |
| Rate This Article: | Add This Article To: |
( Page 4 of 7 )
and Objects">
Perhaps the best way to understand the capabilities and limitations of Web Services is to compare them to other techniques. First, let's compare the consumption of a Web Service to the consumption of a local object. Later, we'll compare Web Services to other distributed application techniques.
Let's look at an example of a simple class called Plane that has private members, public read-write and read-only properties, default and non-default constructors, and a public function.
Public Class Plane
'private members
Private mName As String
Private mPassengers As Integer
Private mRange As Integer
Private mEngines As Integer
Private mTailNumber As String
'read-write properties
Public Property Name() As String
Get
Return mName
End Get
Set(ByVal Value As String)
mName = Value
End Set
End Property
Public Property Passengers() As Integer
Get
Return mPassengers
End Get
Set(ByVal Value As Integer)
If Value < 100 Then
mPassengers = Value
End If
End Set
End Property
Public Property Engines() As Integer
Get
Return mEngines
End Get
Set(ByVal Value As Integer)
mEngines = Value
End Set
End Property
'read-only property
Public ReadOnly Property PlaneTailNumber()
Get
Return mTailNumber
End Get
End Property
'default constructor
Public Sub New()
End Sub
'non-default constructor, takes input parameters
Public Sub New(ByVal TailNumber As String, ByVal Passengers As Integer, ByVal Range As Integer)
mName = "Bonanza Man"
mRange = Range
mPassengers = Passengers
mEngines = 1
mTailNumber = TailNumber
End Sub
'public function
Public Shared Function CalcRange(ByVal Fuel As Integer) As Integer
'Range increase by 10 miles for each gallon of fuel
Dim Range As Integer
Range = Fuel * 10
Return Range
End Function
End Class
|
A piece of code local to this class could access the read-only and read-write properties, both constructors, and the public function. Of course, the private member variables are private to this class and cannot be accessed outside of it.
To use the class, a consuming application would dimension a variable of type Plane and then create a new instance of it; in our example below, we use the parameterized constructor and then display the plane's tail number.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim aPlane As Plane
aPlane = New Plane("N84DL", 4, 200)
MessageBox.Show(aPlane.PlaneTailNumber)
End Sub
|
![]() |
|


