Singleton instance
Monkey Forums/Monkey Programming/Singleton instance
| ||
Hy all. Is it possible using Singleton pattern? im trying using this method: Method GetInstance : IView() If ( _instance = Null ) Then _instance = New View( ) Endif Return _instance End Method But got error then call View.GetInstance(): Method 'GetInstance' cannot be accessed from here |
| ||
make _instance a global and make GetInstance a function and it should work. |
| ||
KaaPex Try to do this,like... [monkeycode]Class ST Field a:Int=23 Global _instance:ST Function Get:ST() If _instance=Null Then _instance=New ST() Endif Return _instance End function End Class Function Main:Int() 'Example Local s:ST=ST.Get() Print s.a s.a=34 Local s1:ST=ST.Get() Print s1.a End Function[/monkeycode] |
| ||
Jesse,you are ahead!:D |
| ||
It's work! Thanks |