oggetto semplice senza metodi

creazione dell'oggetto

Class Car Public Color Public CurrentSpeed Public LightsOn End Class

creazione di un'istanza dell'oggetto

Dim objMyCar Set objMyCar = New Car obj.MyCar.Color = "Red"

oggetto semplice con metodi

creazione dell'oggetto

Class Car Public Color Public CurrentSpeed Public LightsOn Public Sub Accelerate(PercetAccel) CurrentSpeed = CurrentSpeed * (1 + PercentAccel * 0.01) End Sub End Class

creazione di un'istanza dell'oggetto

Dim objMyCar Set objMyCar = New Car obj.MyCar.CurrentSpeed = 30 obj.MyCar.Accelerate(50)

oggetto con proprietà e metodi nascosti

creazione dell'oggetto

Class Car private internal_color private internal_speed private internal_lights private Sub Class_Initialize() internal_color = "WHITE" internal_speed = 0 internal_lights = FALSE End Sub public Property Get CurrentSpeed CurrentSpeed = internal_speed End Property public Property Let CurrentSpeed (ByVal iSpeedIn) internal_speed = iSpeedIn End Property public Property Get Color Color = internal_color End Property public Property Let Color (ByVal strColorIn) internal_color = Ucase(strColorIn) End Property public Sub TurnLightsOn internal_lights = True End Sub public Sub TurnLightsOff internal_lights = False End Sub public Function CheckLights if internal_lights then CheckLights = "ON" else CheckLights = "OFF" endi iF End Function public Sub Accelerate(PercetAccel) Dim sngMultiplier sngMultiplier = (1 + PercentAccel * 0.01) internal_speed = internal_speed * sngMultiplier End Sub End Class

creazione e uso di un'istanza dell'oggetto

<%@ Language=VBScript %> <% Option Explicit %> <HTML><BODY> <!--#include file="CarDefinition.asp"--> <% Dim objMyCar Set objMyCar = New Car Response.Write("My car is " & objMyCar.Color & "<br>") Response.Write("the lights are " & objMyCar.CheckLights & "<br>") objMyCar.CurrentSpeed = 44 Response.Write("the car is travelling at " & objMyCar.CurrentSpeed & ".<P>") objMyCar.Accelerate(25) objMyCar.TurnLightsOn objMyCar.Color = "blue" Response.Write("Now the car is travelling at " & objMyCar.CurrentSpeed & ", ") Response.Write("the lights are " & objMyCar.CheckLights & " and ") Response.Write("the color is " & objMyCar.Color & ".") Set objMyCar = Nothing %>