The Observer of WithEvents
Listening to the screams of COM objects asynchronously.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Observer
ARCANUM SCHOOL: Divination // Monitoring
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// VB PATTERN //
' EventWatcher.cls
Private WithEvents m_cursed As CursedCOMObject
Public Sub Watch(obj As CursedCOMObject)
Set m_cursed = obj
End Sub
Private Sub m_cursed_OnSoulConsumed(ByVal soulID As String)
Debug.Print "Soul " & soulID & " was consumed."
End Sub
The WithEvents keyword is the native realization of the Observer pattern. It binds your code to a COM object’s event dispatch interface, allowing you to react synchronously when the object strikes.
Runic Tags:
#observer
#withevents
#events