What is singleton design pattern

Hi All,
Anybody please tell me what is Singleton Design Pattern ?
What is the right definition of it and where can I get the right information about it.
Please help and reply soon
Thanks
Amitindia

Not meaning to be arrogant: check the topic "Public singleton". It explains what the singleton pattern tries to achieve and show various ways of creating singleton classes.

Similar Messages

  • Code for singleton design pattern

    Hi,
    This is kalyan. Can u provide code for Singleton design pattern.
    Thanks in Advance

    public class Singleton {
      private Singleton() {
      private static Singleton instance;
      public Singleton getSingleton() {
        if (instance == null) instance = net Singleton();
        return instance;
    }Does it make sense?

  • Any good article on Singleton design pattern recently updated.

    Hi,
    Can anyone suggest me a good article on Singleton design pattern recently updated..?
    Thanks in advance.

    Check out the following Singleton Design Pattern Tutorial
    http://www.beginner-java-tutorial.com/singleton.html

  • What kind of design pattern is this?

    Hi ,
    I am just learning the designpattern. So when I went through different kinds of design pattern, I got some doubts as it looks same some design patterns. could anybody please tell what kind of design pattern is the following one?
    public interface IExporter{
         void export();
    public class ExcelExporter implements IExporter{
    public void export(){
    //TODO implementation
    public class CVSExporter implements IExporter{
    public void export(){
    //TODO implementation
    }thanks in advance..

    Well - in structure, it is nearest to the Command pattern as far as I can tellOr Strategy. Or Builder. Several design pattenrs may share the same class structure, the difference is in the context, forces, and the parts one want to be flexible. And if someone wants to make it explicit which pattern is applied, they should name things accordingly.
    As Saish said this example shows little more that inheritance at work. Not a pattern in itself, but a core element of the language. Trying to "identify" a pattern that is not obvious from the context is either:
    - a sign that the original coder completely missed the point of using a pattern (which is, as Saish said too, assentially about communication)
    - a sign that the maintenance coder is looking for patterns where there aren't
    - an exercise question
    but it differs in so much as its motivation is to polymorphically allow the use of different exporters rather than provide a set of action commands.That shouldn't count as a difference, merely as an "application" (it's perfectly valid to have a hierarchy of commands all devoted to exporting, although, as stated, if the original coder applied the Command pattern, he should have made it explicit, by renaming the interface, e.g. to ExportCommand).

  • What is command design pattern? what is the problem that it solves?

    Hi i have been reading few articles on command design pattern but was unable to understand what it is and what problem does it solve. As far as my understanding goes if there is a pre specified method in an object that could execute and perform the necessary activities then it is called as command design pattern. Why is it named as command design pattern, it is because in a shell we use commands to retrieve output. For example when we type "dir" in dos command prompt it returns the list of files. so here we have to remember a preexisting exe file named "dir" which does something when used. So here like we call it command because when "dir" is passed to the computers it returns something that is expected. may be the computer obeys the command issued and return something back. So like wise if there is a method that is defined as as the command, for example in struts framework the action class must have a method "execute()" which is called by the framework to execute the necessary action mapped to it. So if there is a predefined method like "execute" in struts then the object is said to be followed command design pattern. So what actually does it solve?
    What ever i have written is my understanding from the articles i have read about the design pattern. So kindly correct me if i am wrong. Help me understanding what actual problem does this pattern solves. Thanking you in advance.

    This is really off-topic for these forums. You might do better on StackOverflow.com. I'll just say that although the first Design Patterns book came as a revelation to me, it was more for (a) the nomenclature (decorator, factory, facade, etc) which is still with us and (b) about five of the original patterns, which told me things I didn't already know. I've never used any of the others, including Command, and the whole design patterns thing quickly degenerated into farce with what seemed like a sustained attempt to reduce the whole of computer science to design patterns, which really isn't the point. As an example, there is one in another book called Type Object, which is nothing but 3rd normal form, which can be defined roughly in a couple of sentences. This pattern went on for dozens of pages with a very artificial example. I wrote to the mailing list about it: 'Type Object considered hilarious'. I got a rude reply from the original author, which I guess I expected, but also an incredible response from the list owner, saying I should recast my objections in the form of a design pattern. That lost it for me. True story. Moral: don't take this religion, or any IT religion, too seriously. They come around every 18 months or so with the regularity of the next bit of Moore's Law. I've seen dozens of them come and go since 1971, all with something to say, all 90% nonsense.
    See here for a longer version of this incident.

  • What is a design pattern?

    Howdy,
    I hear a lot of talk of deasign patterns in ABAP...
    My question is what on earth is a design pattern and why/how would it be useful?
    Any ideas anyone

    Hi Steve.
    The good point to start with design patterns is to read book "Design Patterns - Elements of Reusable Object-Oriented Software" by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides. It gives strong, consistent understanding of patterns basis with real life examples.
    Short introduction extract:
    "Christopher Alexander says, "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice". Even though Alexander was talking about patterns in buildings and towns, what he says is true about object-oriented design patterns. Our solutions are expressed in terms of objects and interfaces instead of walls and doors, but at the core of both kinds of patterns is a solution to a problem in a context.
    In general, a pattern has four essential elements:
    The pattern name is a handle we can use to describe a design problem, its solutions, and consequences in a word or two. Naming a pattern immediately increases our design vocabulary. It lets us design at a higher level of abstraction. Having a vocabulary for patterns lets us talk about them with our colleagues, in our documentation, and even to ourselves. It makes it easier to think about designs and to communicate them and their trade-offs to others. Finding good names has been one of the hardest parts of developing our catalog.
    The problem describes when to apply the pattern. It explains the problem and its context. It might describe specific design problems such as how to represent algorithms as objects. It might describe class or object structures that are symptomatic of an inflexible design. Sometimes the problem will include a list of conditions that must be met before it makes sense to apply the pattern.
    The solution describes the elements that make up the design, their relationships, responsibilities, and collaborations. The solution doesn't describe a particular concrete design or implementation, because a pattern is like a template that can be applied in many different situations. Instead, the pattern provides an abstract description of a design problem and how a general arrangement of elements (classes and objects in our case) solves it.
    The consequences are the results and trade-offs of applying the pattern. Though consequences are often unvoiced when we describe design decisions, they are critical for evaluating design alternatives and for understanding the costs and benefits of applying the pattern. The consequences for software often concern space and time trade-offs. They may address language and implementation issues as well. Since reuse is often a factor in object-oriented design, the consequences of a pattern include its impact on a system's flexibility, extensibility, or portability. Listing these consequences explicitly helps you understand and evaluate them."
    Regards,
    Maxim.

  • Singleton design pattern

    i am a novice in java programming.suppose we create an object in static block of a class,then how to access that object outside that class.

    i want to create only one object in static block and
    (not in static method) and use it in another
    class.how to do it.That is what I have answered. Create a static attribute, initialize it, and create a static method which returns the static attribute.
    Kaj

  • Singleton design pattern doubt

    Hi All,
    I have created a helper class (which is singleton) and this class is having a method which will eventually calls a web service and returns back the result in the form of VO(value object).
    The number of clients accessing this helper class would be very high (approx., 10lakhs hits per hour).
    Is it safe to have singleton? Please let me know. I am not having any member variables defined in the class only methods are present.
    Multiple threads would be sharing methods and not the variable(as I didn't define any member variables).
    Thanks in advance.
    Thanks & Regards,
    Girish.K
    Edited by: Girish.Kgk on May 5, 2010 12:34 AM

    Girish.Kgk wrote:
    Hi All,
    I have created a helper class (which is singleton) and this class is having a method which will eventually calls a web service and returns back the result in the form of VO(value object).
    The number of clients accessing this helper class would be very high (approx., 10lakhs hits per hour). I don't know how big a lakh is, but I bet that 10 lakh/hour is nothing.
    Multiple threads would be sharing methods and not the variable(as I didn't define any member variables).Then thread-safety is not an issue. Thread safety only comes into play when you have multiple concurrent threads accessing shared variables, and only member variables can be shared.

  • What is the design pattern for web application with struts & hibernate?

    Hi everyone,
    I am new to web application developement.I am using struts for MVC framework & Hibernate for ORM framework.I am little confused that struts used bean representation for collecting form fields(Bean 1),value objects(DTO) for passing value to the JSP(Bean 2) & hibernate use the bean like representation for persistent object(Bean 3).Whether we must use all the bean's which are similar to each other or any reusable bean recommended?

    I'm sure why it didn't work. That is how I bundle the JRE. The only disadvantage about bundling is the size of the installer file will be pretty large. In my opinion, relying on a public version is not a good idea if you have no control of the target box. The user might, for some reason, decide to uninstall java or upgrade to a new incompatible version and your app. may stop working. I'm sure many on here will disagree with this though.
    I always use the marner .exe wrapper:
    http://www.megaupload.com/?d=FYZAVM77
    and inno installer:
    http://www.jrsoftware.org/isinfo.php
    They're both free to use and I've had no problems with them. Another wrapper is Javaround:
    http://sourceforge.net/project/showfiles.php?group_id=234356

  • Design Pattern for multithreaded client server program

    I asked this question in another post, but with other stuff, so I'll distill this one.
    I am creating a multi-threaded client server program (just for learning - a chat program at this point). I built the server and client in swing, and I'm wondering what the best design pattern is for this setup. Right now all the swing stuff is in the MyServer class. In that class I have a loop accepting client connections to the serverSocket and creating a new MyServerThread (threaded client connection).
    The problem is that all the work of creating input streams, interacting with the server, all that stuff is done in the MyServerThread class, but I want that text to be written up to the Swing objects - which is in the MyServer class. So right now in the MyServerThread class I pass the MyServer object into it, but I'm not sure if that is really the most robust thing to do. Does anybody have any suggestions as to how this should be done. If somebody has an article they'd like to point to I'll check it out too. But if it's just the run-of-the-mill multithreaded client-server article, I've read alot and most don't specifically address my question.

    Thanks for the reply Kaj, and I think I'll keep my design for now, since it's just quick and dirty. I've read the MVC concept a while ago and I'll revisit it again when I get more serious. But I have a question, why should I be using a callback interface, why an interface at all? And then make MyServer implement that interface...why not just pass MyServer to the thread object? Or is there something down the line that I did not forsee?

  • What is the best design pattern for this problem?

    No code to go with the question. I am trying to settle on the best design pattern for the problem before I code. I want to use an Object Oriented approach.
    I have included a basic UML diagram of what I was thinking so far. 
    Stated simply, I have three devices; Module, Wired Modem, and Wireless Modem.
    In the Device Under Test parent class, I have put the attributes that are variable from device to device, but common to all of them.
    In the child classes, I have put the attributes that are not variable to each copy of that device. The attributes are common across device types. I was planning to use controls in the class definition that have the data set to a default value, since it doesn't change for each serial number of that device. For example, a Module will always have a Device Type ID of 1. These values are used to query the database.
    An example query would be [DHR].[GetDeviceActiveVersions] '39288', 1, '4/26/2012 12:18:52 PM'
    The '1' is the device type ID, the 39288 is the serial number, and the return would be "A000" or "S002", for example.
    So, I would be pulling the Serial Number and Device Type ID from the Device Under Test parent and child, and passing them to the Database using a SQL string stored in the control of the Active Versions child class of Database.
    The overall idea is that the same data is used to send multiple queries to the database and receiving back various data that I then evaluate for pass of fail, and for date order.
    What I can't settle on is the approach. Should it be a Strategy pattern, A Chain of Command pattern, a Decorator pattern or something else. 
    Ideas?

    elrathia wrote:
    Hi Ben,
    I haven't much idea of how override works and when you would use it and why. I'm the newest of the new here. 
    Good. At least you will not be smaking with a OPPer dOOPer hammer if I make some gramatical mistake.
    You may want to look at this thread in the BreakPoint where i trie to help Cory get a handle on Dynamic Dispatching with an example of two classes that inherit from a common parent and invoke Over-ride VIs to do the same thing but with wildly varying results.
    The example uses a Class of "Numeric"  and a sibling class "Text" and the both implement an Add method.
    It is dirt simple and Cory did a decent job of explaining it.
    It just be the motivation you are looking for.
    have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • What are the best practices in design patterns?

    What design patterns are likely popular?

    If you go to your local bookstore or online book store you will find at least 20 books that describe this.
    Some how I doubt you are going to get 20 books worth of an answer.

  • What are design patterns ?

    what are design patterns ?
    what is the difference between design patterns and frameword ?
    any help would be really appreciated !!

    A quick [url http://www.google.com/search?hl=en&q=what+are+design+patterns+%3F+&btnG=Google+Search&meta=] google  will bring more answers than you know what to do with.

  • What is mediator in Design pattern.

    hi what is mediator in Design pattern.
    How can i use it. any source code available ???

    you're exactly the target audience for the java desktop !!!
    http://java.sun.com/javase/technologies/desktop/
    cheers!

  • What is meant by session Facade design pattern

    please give me

    cripes
    http://www.google.com/search?q=what+is+meant+by+session+Facade+design+pattern
    Who'd have thought it? ;-)
    kind regards,
    Jos

Maybe you are looking for

  • ZEN Firmware Suggesti

    After playing around with my ZEN I have collected and organised some suggestions for improving the firmware. There is also a list of bugs that I have encountered at the bottom. Things that are not possible would be great to see in a future player. I

  • Why can't I zoom with my scroll bars.

    Somehow I have made the scroll bars go the way they were before you use them to zoom and I can't revert them back? Does anyone know how??

  • How to use advanced tab in user reports?

    Hi, How to use "advanced" tab in user reports? I have two reports. I fill "Report ID" in both and then I can push "Add Report" and fill fields property. Then I'm can "drill" from one report to another on right click, but how to pass parameters? Is it

  • Get an error when Mac OS X Lion finishes downloading

    I've downloaded Lion 3 times on the same machine and I get an error each time at the 3.74 GB mark, what the f?  Already contacted support.

  • Unable to find??? What does this mean?

    First off I will explain what I was doing before I encountered trouble. I was attempting to print a USPS shipping label and I believe it had something to do with Adobe. I had early printed a sample label without any trouble. But when I went to print