www.pudn.com > vb-Polymorphic-interface.rar > 测试多态接口.frm, change:2013-02-16,size:2656b


VERSION 5.00 
Begin VB.Form Form1  
   Caption         =   "Form1" 
   ClientHeight    =   3195 
   ClientLeft      =   60 
   ClientTop       =   345 
   ClientWidth     =   4680 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   3195 
   ScaleWidth      =   4680 
   StartUpPosition =   3  '窗口缺省 
   Begin VB.CommandButton Command4  
      Caption         =   "Command4" 
      Height          =   495 
      Left            =   2640 
      TabIndex        =   4 
      Top             =   2640 
      Width           =   1455 
   End 
   Begin VB.CommandButton Command3  
      Caption         =   "Command3" 
      Height          =   495 
      Left            =   2640 
      TabIndex        =   3 
      Top             =   1920 
      Width           =   1455 
   End 
   Begin VB.CommandButton Command2  
      Caption         =   "Command2" 
      Height          =   495 
      Left            =   2640 
      TabIndex        =   2 
      Top             =   1080 
      Width           =   1455 
   End 
   Begin VB.CommandButton Command1  
      Caption         =   "Command1" 
      Height          =   495 
      Left            =   2640 
      TabIndex        =   1 
      Top             =   240 
      Width           =   1455 
   End 
   Begin VB.TextBox Text1  
      Height          =   495 
      Left            =   240 
      TabIndex        =   0 
      Top             =   240 
      Width           =   1935 
   End 
End 
Attribute VB_Name = "Form1" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
 
Option Explicit 
 
Private yVolume As PolyInterface '该类中有AbstractClass的currentVolume属性 , VolumeCheck方法的实现 
 
Private zVolume As AbstractClass 
 
Private Sub Command1_Click() 
  Set yVolume = New PolyInterface 
  Set zVolume = yVolume '将zVolume 设置为yVolume对象中实现的AbstractClass多态接口 
 
  zVolume.currentVolume = Text1.Text ' 调用PolyInterface类实例中的currentVolume属性 (来自于AbstractClass的接口) 
 
  Call zVolume.VolumeCheck ' 调用PolyInterface类实例中的VolumeCheck方法(来自于AbstractClass的接口) 
 
  Call yVolume.Volume(Text1.Text) ' 调用PolyInterface类实例中Public方法Volume 
End Sub 
 
 
Private Sub Command2_Click() '使用原接口代码 
  Set yVolume = New PolyInterface 
  Call yVolume.OldCode(Text1.Text) 
End Sub 
Private Sub Command3_Click() '在原接口代码前后先执行一些其他代码 
  Set yVolume = New PolyInterface 
  Call yVolume.AddCode(Text1.Text) 
End Sub 
Private Sub Command4_Click() '不使用原接口代码而使用新代码 
  Set yVolume = New PolyInterface 
  Call yVolume.NewCode(Text1.Text) 
End Sub