Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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.
observerdesignpattern.zip
ObserverDesignPattern
ObserverDesignPattern
bin
ObserverDesignPattern.exe
ObserverDesignPattern.vbproj.user
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
        Else
            'future object request 
            'return an already created object
            Return s
        End If
    End Function
#End Region
#Region "Color Functions"
    Public Property Color() As Colors
        Get
            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.

License

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 30 May 2005
Article Copyright 2005 by Nigel-Findlater
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid