VB6-Design Mode

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.