Singleton Example : Singleton « Design Patterns « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Design Patterns » Singleton 
27.1.1.Singleton Example
Public Class Singleton
  Private Shared SP As Singleton
  Private InnerList as New Collections.ArrayList()

  Private Sub New()
  End Sub 
  
  Public Shared Function Create() As Singleton
    If SP is Nothing Then SP = New Singleton() 
    Return SP
  End Function

  Public ReadOnly Property List As Collections.ArrayList
    Get
      Return InnerList
    End Get
  End Property
End Class

Module SingletonExample
  Sub Main
    Dim CountValue as Integer
    Dim SP As Singleton = Singleton.Create()
    Dim SP2 As Singleton = Singleton.Create()

    SP.List.Add("First")
    SP.List.Add("Second")
    SP.List.Add("Third")

    For CountValue = To SP2.List.Count - 1
      Console.WriteLine(SP2.List.Item(CountValue).ToString())
    Next
  End Sub
End Module
First
Second
Third
27.1.Singleton
27.1.1.Singleton Example
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.