Click here to Skip to main content
12,304,352 members (69,136 online)
Click here to Skip to main content


29 bookmarked

Using an Observer design pattern to keep multiple forms up to date

, 29 May 2005
This article demonstrates how multiple forms can be updated simultaneously using Singleton and Observer Design Patterns.
Public Class ColorObserver

    Public Shared Event ColorUpdated()
    Private Shared _SelectedColor As Colors
    Public Enum Colors
        Red = 0
        White = 1
        Blue = 2
    End Enum

#Region "Singleton Design Patern"
    REM Use a Singleton Design patern to ensure that this class can only be instanciated once
    Public Shared s As ColorObserver
    Public Shared flag As Boolean

    Private Sub New()
        'private constructor disallowing other to create object directly
    End Sub
    Public Shared Function getSingletonObject() As ColorObserver
        If flag = False Then
            'First instance
            'return a new object
            s = New ColorObserver
            flag = True
            Return s
            'future object request 
            'return an already created object
            Return s
        End If
    End Function
#End Region
#Region "Color Functions"
    Public Property Color() As Colors
            Return _SelectedColor
        End Get
        Set(ByVal Color As Colors)
            _SelectedColor = Color
            RaiseEvent ColorUpdated()
        End Set
    End Property
#End Region

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
Switzerland Switzerland
I am a Software Engineer currently working in a Re Insurance company.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160530.1 | Last Updated 30 May 2005
Article Copyright 2005 by Nigel-Findlater
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid