Single case __java of single case model of Java design pattern

Source: Internet
Author: User
Package Create type _ single case mode _ registration type;
Import Java.util.HashMap;

Import Java.util.Map; /** * Registered Singleton actually maintains an instance of a set of singleton classes, store these instances in a map (register) *, return directly from the factory for a single instance that has already been registered, and register for unregistered, and then return * @author PP */public Class Regsingleton {/** * register, used to hold all registered instances/private static map<string, regsingleton> Map = new H
    Ashmap<string, regsingleton> ();
        Add an instance to the register when the class is loaded static{Regsingleton singleton = new Regsingleton (); Map.put (Singleton.getclass (). GetName (), singleton)//Using reflection}/** * Protected default construction Method */protected Regsingle ton () {}/** * Static Factory method, returning the only instance of the specified Registration object * For a registered direct fetch return, register before it is registered, and then take out the return * * * */Publi
        C Static Regsingleton getinstance (String name) {if (name==null) {name= "Regsingleton"; } if (Map.get (name) ==null) {try {map.put (name), (Regsingleton) class.forname (name). Newi
            Nstance ()); catch (Exception e) {e.printsTacktrace ();
    } return Map.get (name);
    /** * A schematic business method/public String about () {return "hello,i am Regsingleton";

 }
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.