摘要:(200-06-25) VB.NET Singleton 設計模式
特色:主有單一個物件,需將自己的建構子封起來
Public Class SuperMan
'Data Field
Private _name As String = "克拉克"
Private Shared _myself As SuperMan = New SuperMan()
'建構子
Private Sub New()
End Sub
'開放 method ( 找代理 )
Public Shared Function callSuperMan() As SuperMan
Return _myself
End Function
'物件要執行的功能
Public Sub Help(ByVal who As String)
System.Console.WriteLine("去救..." + who)
End Sub
End Class
Module TestAbstractClass
Public Sub Main()
'定義區域變數
Dim emp As Employee = Nothing
'emp = New Employee() 抽象類別
Dim super As SuperMan = SuperMan.callSuperMan()
'物件功能救人
super.Help("露一絲")
End Sub
End Module