0 Replies Latest reply on Jun 23, 2004 7:53 AM by solo

    Singelton pattern

    solo Newbie

      Hi, I've written a simple singleton pattern along with a attribute allows for:

      *@@ singelton
      public class A
      private String m_csDefaultValue = null;

      public A() {}
      public A(String csDefaultValue)
      if (null != this.m_csDefaultValue)
      this.m_csDefaultValue = csDefaultValue;

      public String getDefaultValue() { return this.m_csDefaultValue }
      public void setDefaultValue(String csValue) { this.m_csDefaultValue = csValue; }

      new A("hello world").getDefaultValue(); // hello world
      new A().getDefaultValue(); // hello world
      new A().setDefaultValue("kalle karlsson");

      A a = new A();
      a.getDefaultValue(); // kalle karlsson

      I admit this is to tamper with the singelton pattern a bit but I think it is a more modern version of it and allows for configuration based singeltons instead of hardcoded ones. An yes of course it would be quite possible to allow for a specific method to be marked as singelton returns...

      If interresting would a network based (jgroups) one of interrest?