1. Single-piece Mode
Class: singletonclass Option Explicit
Public Count As Integer
Private Sub Class_initialize ()
If Gsingleton Is Nothing Then
Set Gsingleton = Me
End If
End sub
Public Function Getinstance () As Singletonclass
Set Getinstance = Gsingleton
End Function
Module DeclarationPublicGsingletonAsSingletonclass
2. Method inheritance
Class: imethod
Public Function Setname (name As String )
Setname = Trim ( Ucase (Name ))
End Function
Class: newmethod
Implements imethod
Private Base As Imethod
Private Sub Class_initialize ()
Set Base = New Imethod
End sub
Private Sub Class_terminate ()
Set Base = Nothing
End sub
Private Function Imethod_setname (name As String ) As Variant
Imethod_setname = Base. setname (name)
Imethod_setname = Imethod_setname & " 0001 "
End Function
3: factory model:
Createobject
4: A comunit Design Model Implements itestcontainer
Public Property Get Itestcontainer_testcasenames () As Variant ()
Itestcontainer_testcasenames = Array ( " Teststring " )
End Property
Public Sub Itestcontainer_runtestcase (otestcase As Itestcase, otestresult As Testresult)
Callbyname me, otestcase. Name, vbmethod, otestresult
End sub
Public Sub Teststring (otestresult As Testresult)
End sub
Use testcasenames to expose extended members.
Use methods similar to teststring (same interface parameters) to expand functions.
Use testresult to run through the class processing bus.
Use testrunner to process classes that comply with the itestcontainer interface.
5: Observer Mode
Option Explicit
' Ineteface subject
Public Sub Register (OBS As Observer)
End sub
Option Explicit
'Interface observer
Public SubNotify (msgAs String)
End sub
' Frmmain
Implements subject
Dim CC As Collection
Private Sub Commandmediaclick ()
Dim C As Observer
For Each C In CC
C. Policy Inputbox ( " Caption: " )
Next
End sub
Private Sub Form_load ()
Set CC = New Collection
Dim O As Frm1
Set O = New Frm1
O. ini me
O. Show
Dim Oo As Frm2
Set Oo = New Frm2
OO. ini me
OO. Show
End sub
Private Sub Subject_register (OBS As Observer)
Cc. Add obs
End sub
' Frm1
Implements observer
Public Sub INI (S As Subject)
S. Register Me
End sub
Private Sub Observer_notify (msg As String )
Me. Caption = MSG
End sub
' Frm2
Implements observer
Public Sub INI (S As Subject)
S. Register Me
End sub
Private Sub Observer_notify (msg As String )
Me. Caption = MSG
End sub