I do not understand your implementation of this pattern.
Classically, in single-threaded environments like the flash player,
Singleton is implemented as below (using your nomenclature):
class MyManager {
private static _myManager: MyManager = null;
public static function getInstance(): MyManager {
if(_myManager == null) {
_myManager = new MyManager();
}
return _myManager;
}
private function MyManager() {
// constructor stuff here...
}
}
This works. I use it regularly.
The strange bit in your code is:
if(_myManager==null){
_myManager=this;
}
Since _myManager is a PRIVATE and STATIC property set JUST BEFORE
calling the constructor the FIRST TIME, why should the constructor
attempt to set it? Specially when it does so as an instance property
(ie. Not declaring the Class scope first as in:
MyManager._myManager = this;
What is the advantage of this block?
izk
On Feb 20, 2006, at 9:14 AM, Manuel Saint-Victor wrote:
Jesse,
Here is the getInstance that I am using
private function MyManager() {
// constructor
if(_myManager==null){
_myManager=this;
}
init();
}
public static function getInstance() : MyManager{
if(_myManager==null){
_myManager=new MyManager();
}
return _myManager;
}
I switched the name of the class a bit but everything else is
unchanged in
these two methods.
Mani
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com