Singleton and static class

I found that some guy coded their static classes in their Flash programs such as this:

package {}

class SingletonEnforcer)

}

package {}

SerializableAttribute public class StaticClass extends EventDispatcher {}

private static var _staticClass:StaticClass;

public void StaticClass (singletonEnforcer:SingletonEnforcer) {}

nothing

}

Public Shared function getInstance (): {StaticClass}

if(_staticClass == null)

{

_staticClass = new StaticClass (new SingletonEnforcer());

}

return _staticClass

}

}

}

And these days, I read some Flex project code as:

package {}

public class StaticClass {}

protected public static var _instance:StaticClass;

public void StaticClass () {}

public static class

}

public static void get () of the instance: {StaticClass}

If (_instance == null)

{

_instance = new StaticClass ();

}

return _instance

}

}

}

What is the difference between the two approaches? Why the SingletonEnforcer class is needed in the first case?
Thanks in advance!

singletonEnforcer is not necessary in the first example, and they could use one in the second example, if they wanted. With the help of the enforcer allows to raise an error in the constructor and say an error such as: singleton - use getInstance(); and using the initializer applies appropriate. In the second example, you can simply use the constructor and bypass the getInstance() method and no errors occur. They just leave it up to you, the developer, to use the getInstance(), method.

Tags: Adobe Animate

Similar Questions

  • How to access the static class variable calendar / singleton?

    How can I access a timeline of a static class variable / singleton?

    You can pass any object to display list to your class when instantiating it.  all objects in the display list has a placement property that allows access to the stage and them you can use the correct path/name to your variable.

  • error of static class

    I have a static class:

    package VO
    {
    public class ArrayValues
    {
    private static var instance: ArrayValues = new ArrayValues();

    nominal values will replace the first with English-language versions
    If the user clicks on "Spanish" they will be replaced with
    private var yesNoArray:Array = new Array('1','2');
    private var utilityArray:Array = new Array('1','2');

    public void ArrayValues()
    {
    error ("ArrayValues is called by its instance");
    }

    Public Shared function getInstance (): ArrayValues
    {
    return instance;
    }

    public function getYesNoArray (): Array
    {
    Return yesNoArray;
    }
    public void setYesNoArray(input:Array):void
    {
    yesNoArray = entry;
    }

    It is invoked here:

    import VOS. ArrayValues;
    import VOS. InputData;
    import VOS. InputLabels;

    [Bindable]
    public var saveData:InputData = InputData.getInstance ();

    [Bindable]
    168 public var getArrays:ArrayValues = ArrayValues.getInstance ();
    ...

    It generates this error:

    Error: ArrayValues is called by its instance
    to VO::ArrayValues() [C:\FSCalc\Flex\FSCalc\src\VO\ArrayValues.as:14]
    to VO: ArrayValues$ cinit)
    Global $init () [C:\FSCalc\Flex\FSCalc\src\VO\ArrayValues.as:3]
    components::InputForm() [C:\FSCalc\Flex\FSCalc\src\components\InputForm.mxml:168]
    in FSCalc / _FSCalc_InputForm1_i)
    in FSCalc / _FSCalc_Array6_c)
    ...

    What I am doing wrong?

    PS, it is normal to take almost 10 minutes a) go to your discussions, b) read a reply to a thread and c) come back to the normal discussion?  That seems excessive to me.

    If you try to reach singleton,

    Your manufacture should look like this,

    public void ArrayValues(access:SingletonEnforcer)
    {

    If (access is nothing)
    {
    error ("ArrayValues is called by its instance");
    }

    }

    a variable,

    public static private var _instance: ArrayValues;

    Public Shared function getInstance (): ArrayValues

    {
    If (_instance is nothing)
    {
    _instance = new ArrayValues (new SingletonEnforcer());
    }
    return _instance;

    }

    And another class in the same file,

    class SingletonEnforcer
    {
    }

  • Static class functions: PLS-00801: internal error [phd_get_defn:D_S_ED:LHS]

    Any ideas why this would generate an internal error - referring to a static class function in the constructor of this class parameter signature?

    Test case (on 11.2.0.2) as follows:
    SQL> create or replace type TMyObject is object(
      2          id      integer,
      3          name    varchar2(30),
      4  
      5          static function DefaultID return integer,
      6          static function DefaultName return varchar2,
      7  
      8          constructor function TMyObject(
      9                  objID integer default TMyObject.DefaultID(), objName varchar2 default TMyObject.DefaultName()
     10          )return self as result
     11  );
     12  /
    
    Type created.
    
    SQL> 
    SQL> create or replace type body TMyObject is
      2  
      3          static function DefaultID return integer is
      4          begin
      5                  return( 0 );
      6          end;
      7  
      8          static function DefaultName return varchar2 is
      9          begin
     10                  return( 'foo' );
     11          end;
     12  
     13          constructor function TMyObject(
     14                  objID integer default TMyObject.DefaultID(), objName varchar2 default TMyObject.DefaultName()
     15          )return self as result is
     16          begin
     17                  self.id := objId;
     18                  self.name := objName;
     19                  return;
     20          end;
     21  
     22  end;
     23  /
    
    Type body created.
    
    SQL> 
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject();
      5  end;
      6  /
    declare
    *
    ERROR at line 1:
    ORA-06550: line 0, column 0:
    PLS-00801: internal error [phd_get_defn:D_S_ED:LHS]
    If static class functions are removed from the manufacturer and applied to the place inside the body of the constructor, it works without error. Similarly, you can call the constructor with the functions of the static class as parameters, without causing an internal error.
    SQL> create or replace type TMyObject is object(
      2          id      integer,
      3          name    varchar2(30),
      4  
      5          static function DefaultID return integer,
      6          static function DefaultName return varchar2,
      7  
      8          constructor function TMyObject(
      9                  objID integer default null, objName varchar2 default null
     10          )return self as result
     11  );
     12  /
    
    Type created.
    
    SQL> 
    SQL> create or replace type body TMyObject is
      2  
      3          static function DefaultID return integer is
      4          begin
      5                  return( 0 );
      6          end;
      7  
      8          static function DefaultName return varchar2 is
      9          begin
     10                  return( 'foo' );
     11          end;
     12  
     13          constructor function TMyObject(
     14                  objID integer default null, objName varchar2 default null
     15          )return self as result is
     16          begin
     17                  self.id := nvl( objId, TMyObject.DefaultID() );
     18                  self.name := nvl( objName, TMyObject.DefaultName() );
     19                  return;
     20          end;
     21  
     22  end;
     23  /
    
    Type body created.
    
    SQL> 
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject();
      5  end;
      6  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject(
      5                          objID => TMyObject.DefaultID(),
      6                          objName => TMyObject.DefaultName()
      7                  );
      8  end;
      9  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    Had a look on support.oracle.com and turned toward the top of the specific remarks concerning the use of the static class functions in the signature of the constructor parameter. Known issue? Any other solution in addition to the above?

    Hello

    There is a bug: ""Bug 8470406: CREATING an OBJECT INSTANCE FAILS WITH the ERROR PLS-00801 IN 11 GR 1 material ", it shows the behavior in 11 g but not to the point 10.2." It gives exactly the symptoms you see also, move to the body and it works. But he gave no solution/patch.

    Herald tiomela
    http://htendam.WordPress.com

  • "new static class qualified."

    Hi all

    I have a class of RandomGenerator with a nested public static String class, which extends from CountingGenerator with a nested class public static String, which in turn has a next() method to generate a following string object. Now, how do I actually use, how do I get a reference to the nested class so that I can call the following method. I tried this code, but it throws RuntimeException: code source Uncompilable - qualified new static class:
    public class FillTreeSet {
        public static void main(String[] args) {
            RandomGenerator rg = new RandomGenerator();
            RandomGenerator.String rgs = rg.new String();   //throws the exception
        }    
    }
    It's the RandomGenerator class:
    public class RandomGenerator {
        public static class String extends CountingGenerator.String {
            { cg = new Character(); }
            public String() {}
            public String(int length) { super(length); }
        }
    }
    And it comes to the CountingGenerator class:
    public class CountingGenerator {
        public static class String implements Generator<java.lang.String> {
            private int length = 7;
            Generator<java.lang.Character> cg = new Character();
            public String() {}
            public String(int length) { this.length = length; }
            @Override
            public java.lang.String next() {
                char[] buf = new char[length];
                for (int i = 0; i < length; i++)
                    buf[i] = cg.next();
                return new java.lang.String(buf);
            }
        }
    }
    Thanks in advance.
    PR.

    Since this is a static inner class, you must specify:

    new RandomGenerator.String();
    

    Your code would work if it were a non-static inner class.

  • initializer, instance and static initializer blocks

    Hi guys,.

    I have read the foregoing, mentioned in the JLS and also in a book before, but I still do not understand, what is the use of these. I have sort of a rough idea, but not exactly. I mean, what is the purpose of the initializer for instance and static initializer blocks, how can be useful? I understand that I can run pieces of code that initialize instance and static variables accordingly, but what is the difference then to use a constructor to initialize these areas? Are these pieces of code executed before the execution of any manufacturer, or when otherwise?

    Sorry for my noob, I learn.

    PR.

    Static initializer blocks are executed when the class is loaded, once (a classloader). So that they have some use. Initializers for instance differ a lot of builders (I think that code in the initializers of the instance has been copied to each manufacturer), but they can be useful with anonymous inner classes for example (since you cannot define constructors it (well, you can, but you can't call them)).

    They have a limited use, but it is good to recognize them if you see them.

  • Static class to change TextField

    Hello

    I'm doing a static class that will change the text in a TextField inside a SWF file.

    In this case, I have a MovieClip with a TextField with a message inside. I want to be able to make a class that gives this TextField and a message, what will change in the button.

    Certainly that I forget something obvious, I get the correct trace messages, but the textfield object disappears. The original text is 'Start' and I want to change cela 'OK '. For now I just want to change the text, but then I want to be able to change the text format.

    So far, I have this:

    package

    {

    import flash.display.MovieClip;

    SerializableAttribute public class ChangeTextField extends MovieClip

    {

    public void ChangeTextField(_textField:Object,__text:String):void {}

    }

    public static void change(_textField:TextField,__text:String):void {}

    trace ("CHANGETEXTFIELD" + _textField); Return to 'start '.

    _textField.text = _text;

    }

    }

    }

    In another class, I loaded the SWF and its contents is inside a MovieClip so that I can reference it. To edit the text in the TextField I would do something like:

    ChangeTextField.change (okButton.normal.label_tx, "OK");

    trace (okButton.normal.label_tx. (Text); Returns "OK".

    By the messages trace, all that does what it is supposed to do, but the object TextField disappears.

    Any idea?

    See you soon.

    If you see all traces of planned, make sure that your policy is incorporated.

  • How to get the jar file without knowing his name and any class on the inside?

    Hello, everyone!

    I would like to know if there is a way to get a reference programmatically in the original container without knowing his name and any class it contains. I mean by "initial pot" the pot that was called in the prompt, like this:
    java -jar jarfile.jar
    or in another way, in a graphics system. To be honest, what I really want is to get a reference to the manifest of the jar, but I know that if I can get a reference to the jar I can get a reference to its manifest file. Or if you know a way to get the manifest directly, it would also be useful. So, is there a way to do this?

    Thank you.

    Marcos

    Ah, so you want to find the calling class and get its source code.

    I managed to get the class calling on occasion, but this is probably a somewhat fragile solution. You must extend SecurityManager because getClassContext() is a protected method.

        private static class CallerFetch extends SecurityManager {
    
            public Class getCallerClass() {
                return getClassContext()[3];
            }
        }
        private static CallerFetch callerFetch =
                new CallerFetch();
    
        /**
         * Find the class of the code which called the
         * method that invokes this method.
         * @return The class of the caller's caller
         */
        public static Class getCallerClass() {
            return callerFetch.getCallerClass();
        }
    
  • can we create a static class in actionscript 3.0

    Hi if yes please send me piece of code.

    Thank you

    Hi Julie,.

    There is not specifically a static class in Flex you can declare it at compile time. However, you can have static variables and methods in your class and you can call them by using the class name itself without creating an instance of this class.

    Here is the piece of code...

    package com.constants
    {
    [Bindable]
    public class ConsumerMessageConstants
    {
    public static const = "10000" UNABLE_TO_ENROLL_PLANS_MESSAGE_ID:String
    public static const "10001"; = MARITAL_STATUS_UPDATED_MESSAGE_ID:String
    public static const "10002" = ERROR_IN_EDITING_MARITALSTAUS_MESSAGE_ID:String
    public static const "10003" = SMOKER_STATUS_SAVED_SUCCESSFULLY_MESSAGE_ID:String
    public static const = '10004 '; PASSWORD_RESET_REQUIRED_MESSAGE_ID:String
    public static const "10005; = ADDRESS_UPDATED_SUCCESSFULLY_MESSAGE_ID:String
    public static const "10006; = UNABLE_TO_REMOVE_THIS_DEPENDENT_MESSAGE_ID:String
    public static const "10007; = EMPLOYEE_SALARY_UPDATED_SUCCESSFULLY_MESSAGE_ID:String
    public static const "10008; = ERROR_IN_EDITING_SALARY_MESSAGE_ID:String
    public static const "10009; = PLEASE_SELECT_A_CONSIDER_PLAN_MESSAGE_ID:String
    public static const "10010" = YOU_MUST_CHOOSE_A_PLAN_COVERAGE_LEVEL_MESSAGE_ID:String
    public static const "10011" = PLEASE_SELECT_PLAN_TO_LOCK_PORTFOLIO_MESSAGE_ID:String
    public static const "10012" = DEEPDIVE_INFORMATION_SAVED_SUCCESSFULLY_MESSAGE_ID:String
    public static const "10013" = NO_DATA_TO_DISPLAY_MESSAGE_ID:String
    public static const "10014" = NO_PLANS_AVAILABLE_TO_ENROLL_MESSAGE_ID:String
    public static const "10015" = NO_PLANS_TO_BE_ENROLLED_MESSAGE_ID:String
    public static const "10016 = PASSWORD_CHANGED_SUCCESSFULLY_MESSAGE_ID:String."
    public static const "10017" = NEW_PASSWORD_AND_CONFIRM_PASSWORD_SAME_MESSAGE_ID:String
    public static const "10018; = YOUR_DATA_IS_UPDATED_SUCCESSFULLY_MESSAGE_ID:String
    public static const "10019" = HEALTH_PLAN_IS_UPDATED_SUCCESSFULLY_MESSAGE_ID:String
    public static const = '10020 '; HEALTH_PLAN_IS_ADDED_SUCCESSFULLY_MESSAGE_ID:String
    public static const = '10021 '; MONEY_PLAN_IS_UPDATED_SUCCESSFULLY_MESSAGE_ID:String
    public static const "10022; = MONEY_PLAN_IS_ADDED_SUCCESSFULLY_MESSAGE_ID:String
    public static const = '10023 '; PROTECTION_PLAN_IS_UPDATED_SUCCESSFULLY_MESSAGE_ID:String
    public static const "10024" = PROTECTION_PLAN_IS_ADDED_SUCCESSFULLY_MESSAGE_ID:String
    public static const "10025" = UNABLE_TO_RETRIEVE_PATHS_MESSAGE_ID:String

    Public Shared function func1 (): Void
    {
    ////

    }

    Public Shared function func2 (): Void
    {
    ////

    }
        
    public void ConsumerMessageConstants()
    {
    }
    }
    }

  • Static Classes &amp; events

    Can it only an instance of a class expedition event, or the static class can too?

    We have static class MyManager:

    package managers

    {

    Import mx.rpc.CallResponder;

    import of services. MyDataService;

    Import valueObjects.MyValueObject;

    Public NotInheritable class MyManager

    {

    public static var updateDataResult:CallResponder = new CallResponder();

    private static var myDataService:MyDataService = new MyDataService ();

    private static var myValueObject:MyValueObject = new MyValueObject();

    Public Shared function updateMyDataService (): void {}

    updateDataResult.token = myDataService.update (myValueObject);

    }

    }

    }

    And the other class which calls:

    import managers. MyManager;

    MyManager.updateMyDataService ();

    MyManager.updateDataResult.addEventListener (ResultEvent.RESULT, resultReceived);

    and this event listener does not work.

    Hi Banditizm,

    Yes you can even send your static callResponders events, but I think that the difficulty you might face you cannot capture or listen to events sent.

    You can do something, you can send these events w.r.t. systemManager and also listen to these WRT events there.

    I mean your shipment to help call the event as below...

    systemManager.dispatchEvent (new Event ("dataLoadComplete"));

    And you can listen in your mxml or as .as file below...

    systemManager.addEventListener ("dataLoadComplete", onDataLoadComplete);

    Thank you

    Jean Claude

  • IPSec Tunnel between Cisco 2801 and Netscren 50 with NAT and static

    Hello

    My problem isn't really the IPSec connection between two devices (it is already done...) But my problem is that I have a mail server on the site of Cisco, who have a static NAT from inside to outside. Due to the static NAT, I do not see the server in the VPN tunnel. I found a document that almost describes the problem:

    "Configuration of a router IPSEC Tunnel private-to-private network with NAT and static" (Document ID 14144)

    NAT takes place before the encryption verification!

    In this document, the solution is 'routing policy' using the loopback interface. But, how can I handle this with the Netscreen firewall. Someone has an idea?

    Thanks for any help

    Best regards

    Heiko

    Hello

    Try to change your static NAT with static NAT based policy.

    That is to say the static NAT should not be applicable for VPN traffic

    permissible static route map 1

    corresponds to the IP 104

    access-list 104 refuse host ip 10.1.110.10 10.1.0.0 255.255.0.0

    access-list 104 allow the host ip 10.1.110.10 all

    IP nat inside source static 10.1.110.10 81.222.33.90 map of static route

    HTH

    Kind regards

    GE.

  • ASA 5500 and static NAT 1-to-1

    We currently have a pair of s ASA 5500 failover providing firewall & nat with inside, outside and the dmz interfaces. We do PAT interface for most of the internal to the external and static connections 1-to-1 NAT for specific hosts that need to accept connections from the outside inside. The space of the static nat is a 27 which includes the address of the external interface. It's that everything is working properly.

    However, we are out of space for the static NAT to this/27. I would like to be able to add a different network, probably another 27, for the more static NAT but I'm a hard time to find the best way to do it. Is this possible with a network that does not include the external interface on the ASA?

    Here are some of our current NAT config:

    Global interface 10 (external)

    NAT (inside) 10 0.0.0.0 0.0.0.0

    (dmz1, outside) static dmz1-net-net dmz1 netmask 255.255.255.224

    static (inside, dmz1) 192.168.0.0 192.168.0.0 netmask 255.255.0.0

    static (inside, dmz1) 10.0.0.0 10.0.0.0 netmask 255.0.0.0

    static (inside, outside) xx.yy.164.15 192.168.98.46 netmask 255.255.255.255

    static (inside, outside) xx.yy.164.8 192.168.98.47 netmask 255.255.255.255

    static (inside, outside) xx.yy.164.14 192.168.98.48 netmask 255.255.255.255

    static (inside, outside) xx.yy.164.13 192.168.101.50 netmask 255.255.255.255

    Thank you very much...

    Hello

    The correct syntax for the proxyarp activation will be

    No outside sysopt noproxyarp

    http://www.Cisco.com/en/us/products/ps6120/products_command_reference_chapter09186a00805fb9e9.html#wp1111405

  • How to generate the alert when pageitem move on the page? and what class boss be use to move pageitem

    How to generate the alert when pageitem move on the page? and what class boss be use to move pageitem

    Hi Philippe,.

    You can see the kDocBoss for the ClassID with the PMIID IID_ITRANSFORM_DOCUMENT kLocationChangedMessage.

    Markus

  • Crackling and static

    I just upgraded my iMac with OS X El Capitan. Now when I change my podcast, recorded in multi tracks, I hear crackling and static. When I export the file to a drive MP3 the problem isn't here. Any suggestions?

    Also, now when I switch back between wavelength and multitrack forms, it takes seconds to change (he used to make the quick switch) and the rotation color wheel appears during the shift.

    The attached note warning appears in a media window and hides. I wonder if it's related.Screen Shot 2015-12-01 at 5.26.13 PM.png

    You are using an external audio interface or map of its Apple built in?

    In any case, El Capitan, from all reports, was a disaster in terms of audio performance.  If you do not have the latest version of El Capitan, download the upgrade... It fixes some of the audo related issues.  (But, alas, not all.)  It is not just an audition... many DAW and audio hardware companies have issued warnings not to go yet.  Indeed, the last bug fix worked on hearing for most users.

    You can try to increase the latency/Buffer setting in Edition/Preferences/Audio Hardware.  There's a chance that might help.

    In addition, you may need to wait for the next difficulty of Apple bug... or downgrade to the previous version of the operating system.

  • Shrunken and static site in the browser

    My Preview button on the site I'm building looks normal, but my site on browser view is narrowed and static. Any ideas? Yesterday, I tried to show someone on browser by copying the link after the test on my own computer where it was ok? Each page is now frozen. Help!

    Please share the URL of the site.

Maybe you are looking for

  • Where can I find all the drivers Win 7 for Satellite L40 - 14F

    Hi allFind all the drivers for L40 laptop model 14F for windows 7 OS? Is that someone has installed this OS? Is it possible to have some problems during installation? Thank you very much.

  • Need Ethernet controller driver

    I bought a new laptop HP Pavilion g6-2314eeand I don't want to install windows 8I want to install windows 7 64 bit and I can't find the drivers I tried to install them and its worked, but I have ethernet problem that I can not find the ethernet contr

  • Flight Simulator 3 and other games running slowly in Windows 7.

    Original title: Sims 3 (and other games works incorrectly) suddenly running slow. I'll try to make this as brief as possible while providing for. When I got to Windows 7, the sims 3 worked perfectly. all the graphics on the top and so on. I can't qui

  • QTimer and qmlRegisterType

    I think it's time for me to consult the world forum on my problem. It seems so simple and yet I could not find the cause of the problem. I started having problems after you install the SDK version Gold I use QTimer on stunts. In my .cpp, I registered

  • BlackBerry Smartphones factory reset

    Does anyone know how can I reset my phone to factory setting?