2 Replies Latest reply: Mar 1, 2012 6:41 PM by safarmer RSS

    Singleton pattern

    858245
      I am having one class that should be shared between multiple modules. Therefore I defined it with singleton pattern. Now I am wandering is this the optimal solution.
      Is it better to remove this singleton pattern and share this object via method parameter. I like the singleton pattern more.
        • 1. Re: Singleton pattern
          Umer
          jz wrote:
          I am having one class that should be shared between multiple modules. Therefore I defined it with singleton pattern. Now I am wandering is this the optimal solution.
          Is it better to remove this singleton pattern and share this object via method parameter. I like the singleton pattern more.
          If the particular class's functionality is being used in multiple classes then you might use inheritance as well.
          • 2. Re: Singleton pattern
            safarmer
            Hi,

            Don't use a singleton :) Simply make the methods and fields public static. This is more efficient. You don't need the overhead of the object instance. It is also faster in respect to firewall/context security checks so execution time will be faster as well.

            FYI, Inheritance is also slower in JC so for performance critical applet it should be avoided if possible (from memory, the same goes for interfaces)

            Cheers,
            Shane