Invoke constructor of a static class

Hi,
I have this constant class and a constructor.
public final class dddd {
public static final String YES="Y";
private dddd(){...}
My question is, when would the constructor be invoked, if the constant class would never be instantiated?
Would this
x = dddd.YES
invoke the dddd constructor?
Thanks.
JL

Not sure what a "constant" class is - if you mean final, that simply means you cannot extend the class. The static String varibale YES is simply a class variable. The constructor is private, so, I assume that the only way the constructor would be invoked is if somewhere in one of the static method of this class you have a line that says "new dddd()".
Lee

Similar Messages

  • 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 that class constructor's 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 the static class functions are removed from the constructor and applied instead inside the constructor body, it works without error. Likewise you can call the constructor with the static class functions as parameters, without an internal error resulting.
    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 quick look on support.oracle.com and did not turn up any specific notes dealing with the use of static class functions in the parameter signature of the constructor. Known issue? Any other workaround besides the one above?

    Hi,
    there is a bug: "Bug 8470406: OBJECT INSTANCE CREATION FAILS WITH ERROR PLS-00801 IN 11GR1", it shows the behaviour in 11g but not in 10.2. It gives exactly the symptoms you also see, move it to the body and it works. But there is no solution/patch given.
    Herald ten Dam
    http://htendam.wordpress.com

  • Class constructor is actually "static" method, as Bruce Eckel says?

    <Thinking in java> chapter 7 :
    Even though constructors are not polymorphic (they?re actually static methods, but the static declaration is implicit), it?s important ...
    Are constructors actually static methods? I do not think so. static method can only manipulate static members, but constructor can also deal with non-static members. In other words, constructor always associate with a object, while static method always associate with a class.
    Why Mr. Eckel says that constructors are static?

    From the JLS ?8.8.3
    A constructor is always invoked with respect to an object, so it makes no sense for a constructor to be static, so no they are not.
    Are constructors actually static methods?Constructor declarations are not members. Members are defined as the set fields, methods, nested classes and interfaces(JLS ?8). So they are not methods.

  • Static class error

    I have a static class:
    package VO
        public class ArrayValues
            private static var instance:ArrayValues = new ArrayValues();
            // dummy values will be first replaced with English versions
            // if the user clicks "Spanish" they will be replaced with that
            private var yesNoArray:Array = new Array('1','2');
            private var utilityArray:Array = new Array('1','2');
            public function ArrayValues()
                throw Error("ArrayValues is called by its instance");
            public static function getInstance():ArrayValues
                return instance;
            public function getYesNoArray():Array
                return yesNoArray;
            public function setYesNoArray(input:Array):void
                yesNoArray = input;
    It is invoked here:
            import VO.ArrayValues;
            import VO.InputData;
            import VO.InputLabels;
            [Bindable]
            public var saveData:InputData = InputData.getInstance();
            [Bindable]
    168       public var getArrays:ArrayValues = ArrayValues.getInstance();
    It produces this error:
    Error: ArrayValues is called by its instance
        at VO::ArrayValues()[C:\FSCalc\Flex\FSCalc\src\VO\ArrayValues.as:14]
        at VO::ArrayValues$cinit()
        at global$init()[C:\FSCalc\Flex\FSCalc\src\VO\ArrayValues.as:3]
        at components::InputForm()[C:\FSCalc\Flex\FSCalc\src\components\InputForm.mxml:168]
        at FSCalc/_FSCalc_InputForm1_i()
        at FSCalc/_FSCalc_Array6_c()
    What am I doing wrong?
    PS, is it normal to take almost 10 minutes to a) go to your discussions, b) read one response to one thread and c) get back to the normal discussion?  That seems excessive to me.

    Sorry for the late reply.  I've just got back to this project after the usual "an emergency" stuff.
    Yes, I'm looking to create a singleton.  I want to pass values around without having to have monster long parameter lists for the various components.
    I based the Flex I have on a web page and noted it is similar to the java idea, but not identical based on that page.
    I want to make sure I understand the theory behind the code.
    public function ArrayValues(access:SingletonEnforcer)
         if ( access == null )
              throw Error("ArrayValues is called by its instance");
    This is the constructor for the class which has the same name as the file it is in.  A parameter is passed of the type "SingletonEnforcer" and is then tested to see if it were ever invoked.  If it were, an error is created with a string which will be written to the console.
    Next, a variable local to this class is created that will be of the type "ArrayValues" to hold the various arrays.  BTW, either this will have to be expanded or a parallel class created to hold the Spanish values.
    static private var _instance  :  ArrayValues;
    Next, the actual work horse and true "constructor" is made.  This will either allocate a new instance of the class if it doesn't already exist or instantiate it if it doesn't.  I am confused by the second class, however, when it is created the first time.  This class is included in this file?  Doesn't the file name have to match the class?

  • Static classes slower?

    ok, I'm stumped understanding what java is doing... consider the following:
    public static void main(String[] args) {
              //create the main frame and display it
              long start = System.currentTimeMillis();
             JFrame content = MainFrame.getInstance();
             System.out.println("creating took " + (System.currentTimeMillis() - start) + " milliseconds");
             content.show();
         }As expected, this code will pop up my GUI and report the time it took to load it, say 15 seconds. However, I also have time reported in the constructor of the MainFrame class. MainFrame thinks that it takes only 10 seconds to execute instead of 15 seconds. Can anyone offer an explination as to what java is doing to lose so much time and any possible way to resolve the issue?

    OK, JLS has almost nothing to say about class loading, but the VM spec does. Section 5.3: "Creation of a class or interface C denoted by the name N consists of the construction in the method area of the Java virtual machine (�3.5.4) of an implementation-specific internal representation of C. Class or interface creation is triggered by another class or interface D, which references C through its runtime constant pool. Class or interface creation may also be triggered by D invoking methods in certain Java class libraries (�3.12) such as reflection."
    And as it happens the part I was talking about is not part of loading, but linking:
    "5.4.1 Verification
    The representation of a class or interface is verified (�4.9) to ensure that its binary representation is structurally valid (passes 2 and 3 of �4.9.1). Verification may cause additional classes and interfaces to be loaded (�5.3) but need not cause them to be prepared or verified."
    Class.forName says "Given the fully qualified name for a class or interface (in the same format returned by getName) this method attempts to locate, load, and link the class or interface... The class is initialized only if the initialize parameter is true and if it has not been initialized earlier."
    So, the long answer seems to be that when you call Class.forName on a class, it and every class it needs will be recursively loaded and linked, but not necessarily intialized.

  • Invoke a method in one class from a different class

    I am working on a much larger project, but to keep this simple, I wrote out a little test that would convey the over all theory of the program.
    What I am doing is starting out with a 2 JFrames and a Class. When the program is launched, the first JFrame opens. In this JFrame is a label and a button. When the button is clicked, the second JFrame opens. This JFrame has a textField and a button. The user puts the text in the textField and presses the button. When the button is pushed, I want the text that was just put in the textField, to be displayed in the first JFrame's label. I am trying to invoke a method in the first JFrame from the second, but nothing happens. I have also tried making the Class extend from JFrame1 and invoke it from there, but no luck. So, how do I invoke a method in a class from a different class?
    JFrame1 (I omitted the layout part. I made this in Netbeans so its pretty long)
    public class NewJFrame1 extends javax.swing.JFrame {
         private NewClass1 nC = new NewClass1();
         /** Creates new form NewJFrame1 */
         public NewJFrame1() {
              initComponents();
              jLabel1.setText("Chuck");
         public void setLabels()
              jLabel1.setText(nC.getName());
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewJFrame2 j2 = new NewJFrame2();
         j2.setVisible(true);The class
    public class NewClass1 {
         public static String name;
         public NewClass1()
         public NewClass1(String n)
              name = n;
         public String getName()
              return name;
         public void setName(String n)
              name = n;
    }The second jFrame
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewClass1 nC = new NewClass1();
         NewJFrame1 nF = new NewJFrame1();     
         nC.setName(jTextField1.getText());
         nF.setLabels();
         System.out.println(nC.getName());At this point I am begging for help. I have been trying for days to figure this out, and I just feel like I am not getting anywhere.
    Thanks

    So, how do I invoke a method in a class from a different class?Demo:
    public class Main {
        public static void main(String [] args) {
         Test1 t1 = new Test1();
         Test2 t2 = new Test2();
         int i = t1.method1();
         String s = t2.method2(i);
         System.out.println(s);
    class Test1 {
        public int method1() {
         return 10;
    class Test2 {
        public String method2(int i) {
         if (i == 10)
             return "ten";
         else
             return "nothing";
    }Output is "ten".
    Edited by: newark on May 28, 2008 10:55 AM

  • Static Classes/Methods vs Objects/Instance Classes/Methods?

    Hi,
    I am reading "Official ABAP Programming Guidelines" book. And I saw the rule:
    Rule 5.3: Do Not Use Static Classes
    Preferably use objects instead of static classes. If you don't want to have a multiple instantiation, you can use singletons.
    I needed to create a global class and some methods under that. And there is no any object-oriented design idea exists. Instead of creating a function group/modules, I have decided to create a global class (even is a abstract class) and some static methods.So I directly use these static methods by using zcl_class=>method().
    But the rule above says "Don't use static classes/methods, always use instance methods if even there is no object-oriented design".
    The book listed several reasons, one for example
    1-) Static classes are implicitly loaded first time they are used, and the corresponding static constructor -of available- is executed. They remain in the memory as long as the current internal session exists. Therefore, if you use static classes, you cannot actually control the time of initialization and have no option to release the memory.
    So if I use a static class/method in a subroutine, it will be loaded into memory and it will stay in the memory till I close the program.
    But if I use instance class/method, I can CREATE OBJECT lo_object TYPE REF TO zcl_class then use method lo_object->method(), then I can FREE  lo_object to delete from the memory. Is my understanding correct?
    Any idea? What do you prefer Static Class OR Object/Instance Class?
    Thanks in advance.
    Tuncay

    @Naimesh Patel
    So you recommend to use instance class/methods even though method logic is just self-executable. Right?
    <h3>Example:</h3>
    <h4>Instance option</h4>
    CLASS zcl_class DEFINITION.
      METHODS add_1 IMPORTING i_input type i EXPORTING e_output type i.
      METHODS subtract_1 IMPORTING i_input type i EXPORTING e_output type i.
    ENDCLASS
    CLASS zcl_class IMPLEMENTATION.
      METHOD add_1.
        e_output = i_input + 1.
      ENDMETHOD.
      METHOD subtract_1.
        e_output = i_input - 1.
      ENDMETHOD.
    ENDCLASS
    CREATE OBJECT lo_object.
    lo_object->add_1(
      exporting i_input = 1
      importing e_output = lv_output ).
    lo_object->subtract_1(
      exporting i_input = 2
      importing e_output = lv_output2 ).
    <h4>Static option</h4>
    CLASS zcl_class DEFINITION.
      CLASS-METHODS add_1 IMPORTING i_input type i EXPORTING e_output type i.
      CLASS-METHODS subtract_1 IMPORTING i_input type i EXPORTING e_output type i.
    ENDCLASS
    CLASS zcl_class IMPLEMENTATION.
      METHOD add_1.
        e_output = i_input + 1.
      ENDMETHOD.
      METHOD subtract_1.
        e_output = i_input - 1.
      ENDMETHOD.
    ENDCLASS
    CREATE OBJECT lo_object.
    lo_object->add_1(
    zcl_class=>add_1(
      exporting i_input = 1
      importing e_output = lv_output ).
    lo_object->subtract_1(
    zcl_class=>subtract_1(
      exporting i_input = 2
      importing e_output = lv_output2 ).
    So which option is best? Pros and Cons?

  • Dynamic or Static Class

    Dynamic or Static Objects
    It seems to me there is a big cliff at the point of deciding to instantiate your class at runtime or static load
    on start-up.
    My swf apps have a pent-up burst that happens a couple seconds into the run. I think I get this on most
    web pages that have flash banners.
    Flash apps that have a loader bar can take 60 secs. These ones usually come on with a bang with a lot of
    high quality graphics.
    Therer is a big processor spike at start-up with the browser loading http page. Flash seems to want a big spike
    with its initial load. The javascript embed doesn't help either.
    How to get a smooth start-up? Me English good.
     

    This seems like a matter of correctness, only indirectly relating to speed.
    The speed that a SWF loads from a web page is determined by many things, like server connection speed, client connection speed, browser cache size, client RAM, etc.  Having static vs. dynamic classes would not impact this very much.
    First of all, "static objects" is kind of an oxymoron because you can't instantiate (create an object) of a static class.  I would say that having static variables/methods in a class is usually when you want some shared values/functionality without requiring an actual object (taking up memory) -- although static practices certainly extend beyond just this.  I always try to think of a Math class.  You wouldn't have to have to say m = new Math() just to use some common methods (square, sin, cos, etc.) or values (pi, e, etc.).  They become kind of like "global constants/methods" in a sense (not to invoke the debate over correctness of that wording).
    In short, it's more of a memory issue, which will like not have much influence over loading speed.  If you want to improve your loading speed, you can try to delay the creation of your objects based on certain events instead of having them all load at startup.
    How to get a smooth start-up? Me English good.

  • Singleton Vs Static Class

    Hi,
    Kindly excuse if my question annoys anyone in the forum.
    Compared to a singleton class we can always have a class and all methods as static?
    Wouldnt that be the same as Singleton.
    Also looking at Runtime class, its a Singleton. Just thinking if Runtime class could be a class with this static methods instead of making the constructor private .

    I thought I read somewhere that however you implement your singletons, client code shouldn't break if later you decide that you don't need/want a singleton for that class anymore.I agree with that principle.
    This requires that the client code never calls the getInstance() method, and the best way to make sure of that is that the client code does not depend on the singleton class, but on an interface that the singleton class implements.
    (Speaking for myself, I can assure you that I never thought that deeply about it, but continuing...)I have thought a lot about Singletons, specifically when contemplating flaying myself alive for putting them prematurely where they weren't really needed (not to mention some of my colleagues' choice, for fear my message would deserve editing out by moderators).
    I have come to the conclusion that Singleton is overhyped, probably because it's one of the simplest patterns, and the first one people are taught as a way to illustrate the very concept of "design pattern". And overused because it feels so natural to use the first and simplest pattern one has learnt.
    I'm not claiming Singleton has no merits (I used to claim that on this forums). I'm claiming most usages I've seen of Singleton were not based on a careful consideration of the real merits.
    If we implement our singletons (who have state) as "static classes", aren't we violating this?Ah, OK, I get it now: if someday you need to have several copies of the states with different values, you could always "de-singletonize" the singleton, with minimal impact for properly-written client-code, as you point out, whereas you couldn't justas easily "de-staticize" the static calls.
    Indeed that's an argument when evaluating whether making a method static: it statically (1) binds the client code to the implementation class.
    (1) not a pun, merely the very justification for the term static as a keyword.
    J.

  • Constructor of package protected class

    Why has class Test no constructor when trying to get the default constructor by reflection.
    class Test {
         public static void main(String[] args){
              try {
                   Class test=Test.class;
                   Constructor[] ctor= test.getConstructors();
                   System.out.println(ctor.length);
              } catch (Exception e) {
                   e.printStackTrace();
    }

    Returns:
    the array of Class objects representing all the
    the declared members of this classWrong citation:
    Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. An array of length 0 is returned if the class has no public constructors, or if the class is an array class, or if the class reflects a primitive type or void.

  • Please! WHY? Why does the main class cannot find symbol symbol : constructor Car(double) location: class Car?

    Why does the main class cannot find symbol symbol : constructor Car(double) location:
    class Car .. ??
    class Car
    { //variable declaration
    double milesStart; double milesEnd; double gallons;
    //constructors
    public Car(double start, double end, double gall)
    { milesStart = start; milesEnd = end; gallons = gall; }
    void fillUp(double milesE, double gall)
    { milesEnd = milesE; gallons = gall; }
    //methods
    double calculateMPG()
    { return (milesEnd - milesStart)/gallons; }
    boolean gashog() { if(calculateMPG()<15) { return true; } else { return false; } }
    boolean economycar() { if(calculateMPG()>30) { return true; } else { return false; } } }
    import java.util.*; class MilesPerGallon
    { public static void main(String[] args)
         double milesS, milesE, gallonsU;
         Scanner scan = new Scanner(System.in);
         System.out.println(\"New car odometer reading: 00000\");
          Car car = new Car(milesS); car.fillUp(milesE, gallonsU);
         System.out.println(\"New Miles: \" + milesE); milesE = scan.nextDouble();
         System.out.println(\"Gallons used: \" + gallonsU);
         gallonsU = scan.nextDouble();
         System.out.println( \"MPG: \" + car.calculateMPG() );
         if(car.gashog()==true) { System.out.println(\"Gas Hog!\");
          if(car.economycar()==true) { System.out.println(\"Economy Car!\");
         } System.out.println(\"\");
         milesS = milesS + milesE;
         System.out.println(\"Enter new miles\");
          milesE = scan.nextDouble();
         System.out.println(\"Enter gallons used: \");
          gallonsU = scan.nextDouble();
         car.fillUp(milesE, gallonsU);
         System.out.println(\"Initial miles: \" + milesS);
         System.out.println(\"New Miles: \" + milesE);
         System.out.println(\"Gallons used: \" + gallonsU);
         System.out.println( \"MPG: \" + car.calculateMPG() );
         System.out.println(\"\"); } }

    Why does the main class cannot find symbol symbol : constructor Car(double) location:
    class Car .. ??
    Please tell us which line of code you posted shows 'Car (double)'.
    The only constructor that I see is this one:
    Car(double start, double end, double gall)

  • Invoke overriden method in grandparent class(wth trivial example)

    Hi,can any one help? Please read the following trivial example
    class BaseA{
    public void showName(){
    System.out.println("This is BaseA");
    class BaseB extends BaseA{
    public void showName(){
    System.out.println("This is BaseB");
    class Child1 extends BaseB{
    public void showName(){
    System.out.println("This is Child1");
    public void showParentName(){
    super.showName();
    public void showGrandName(){
    //How can I invoke showName() method in grandparent class BaseA
    public class Test2{
    public static void main(String arg[]){
    Child1 obj1= new Child1();
    obj1.showName();
    obj1.showParentName();
    I remember I read a book that mentions how to get around this trouble,but it is really long time ago,can anyone help? a million of thanks

    There might be better way to this but might be below is also work
    class BaseA{
    public void showName(){
    System.out.println("This is BaseA");
    class BaseB extends BaseA{
    public void showName(){
    System.out.println("This is BaseB");
    public void showParentName(){
    super.showName();
    class Child1 extends BaseB{
    public void showName(){
    System.out.println("This is Child1");
    public void showParentName(){
    super.showName();
    public void showGrandName(){
    //How can I invoke showName() method in grandparent class BaseA
    super.showParentName();
    public class Test2{
    public static void main(String arg[]){
    Child1 obj1= new Child1();
    obj1.showName();
    obj1.showParentName();
    obj1.showGrandName();

  • Classloading within Webstart plus static classes

    Hi folks!
    I've a big problem in a software project in "migrating" a normal client-server-RMI-SWT-application to be 100% webstart compatible.
    Everything works really fine except for dynamic classloading on demand.
    The system currently is packaged in some jars.
    Depending on the mask shown to the screen, the system looks for a "customize" class inside the resources. If it finds one, it loads and then does a "defineClass" and then calls a method via the "invoke" mechanism.
    The classes are kind of standardized.
    The problem is, that the "refering" classes from the - let's say - main application are mostly static.
    The called class then tries to call the "namespace" of these classes but only get's null objects - no matter what object it was.
    Run as a normal application - the whole system is working perfectly.
    So as a "big picture", I have the following construct:
    calling Client-Application + Classloader, using a static class for saving object data.
    defining content of one of these static classes:
    DemoObject.setFoobar("Hello world");
    ClassLoader .....
    getResourceAsStream("com/foobar/demo/customizeLogic.class");
    defineClass(byte[] blablablabla,....)
    findMethod.....
    myMethod.invoke(....)inside the dynamic loaded customizeLogic class we do the following
    String demo = DemoObject.getFoobar();
    // this results now into NULL
    // even the ClassLoader is manually loading all java.* plus all other classes because it seems to have a securitymechanism not to share the class-space.I already tried to set the classloader to all variants like SystemClassLoader, ContextClassLoader etc.
    -- but, none worked. I cannot share the same ClassLoader-Resources with the main and "fixed" application... :-(
    Does anyone have a clue or needs more information? I can post some sourcecode also.
    Thorsten

    Hi folks!
    For the most of our problems we're now doing it as "keep it simple".
    I'm just making a Class.forName - "Loading" which works good for alle the classes out of the jars.
    PLUS the setSecurityManager tag - yup.
    During the last weeks I wasn't able to reply because the project ate too much time.
    We'll split the classloading into two or more or less 3-4 parts. One is for the WEBSTART - Edition and one for "normal Client" version. The webstart version we'll split for loading classes vs. loading "normal" resources out of the jars... this will give us flexibility while being able to solve all our problems for now...
    Regards,
    Thorsten

  • Static Class in Java

    Hi All,
    I have gone through en number of web-sites but i don't get a clear definition and a clear cut picture about static class in java
    I had plenty of questions in my mind. Somebody here - Java gurus and experts kindly please help me to understand about these things.
    What is static class ? When to declare a class as Static ? What is the difference between a singleton class and a static class ? It is allowing to create an instance of a static class . why ?
    Thanks,
    With Love,
    J.Kathir

    Sometimes you want to use a class merely as a place to put utility methods and/or constants. Such classes are never instanciated. There's no special syntax, it's simply a class consisting of static methods, and perhaps static fields. You give it a single private constructor so it can't be accidentally instanciated.
    In use it's not that different from a singleton. Generally I'd use a singleton if there was going to be non-constant global data values in it.

  • Singleton pattern class and static class

    Hi,
    what is difference between the singleton pattern class and static class ?
    in singleton pattern, we declare a static member[which hold one value at a time] ,static method[ which return static member value] and a private constructor[not allow to direct instantiation]. My words are -- as a singleton pattern we implement static class .
    so can we say a singleton pattern is static class it means both are same or is any difference between these two ??

    malcolmmc wrote:
    On several occasions I've had to convert a static (never instanceated) class to a singleton type, for example because I realise I need an instance per thread, or I decide to make a program more modular, with more than one configuration.
    I've never done the opposite.
    So generally I favour the singleton if there any "state" involved, because it's more flexible in unanticipated directions. It also gives extra flexibility when building tests, especially if you program to an interface.Total agreement; if anything it is dead hard to override static method logic with mock code in unit tests (I had to do it by keeping the static methods in place but making them internally use a singleton instance of itself of which the instance variable could be overwritten with a mock implementation for unit testing purposes...).
    'Static classes' and/or methods are great for very simple util functions, but I wouldn't use them for anything other than that.

Maybe you are looking for

  • Replacing keyboard keys

    Am I able to go to an Apple store and have a few keyboard keys replaced? A few of them have become sticky due to a minor liquid spill, (after clean-up) but are still fully functioning.

  • How can I handle function pointer in Java?

    Is there any class/methods which can be used to implement function pointers in java.? If yes pliz, help me to get in.

  • Using ITrip with Bluetooth Speakers

    Hi, I want to listen to the music on my IPhone while I am in my car but I also want to be able to make and receive calls. At the moment I make and receive calls through a Visorlite which is attached to my sun visor and bluetooth through my phone. I h

  • Unable to enter serial after re-install

    I had the tech suite installed and working correctly since last November when I downloaded it. I had a disk crash and I tried to re-install on the new hard drive. When I entered the serial number it failed to take. I then talked to customer support w

  • Currency Translation. Unexpected result with currency transl indicator 1

    Dear Experts, Durring currency translation we get the following result: Company  ConsProfitC  PostL     Item         MovType  TransIndLocCur  ValueTransCur       ValueLocCur           ValueGroupCur C0803     DUMMY        00          100001     600