oop - How to create an instance in java based on specific input? Implementation of Singleton pattern -


suppose have crypto class.

public class crypto{      // method returns instance of crypto class key.     // if instance key hasn't been created new instance created.     // if created key same instance returned.      public static crypto getinstance(string key){      }  } 

how implement pattern? mean singleton design pattern different instances different keys , save instance?

i think can use map :

    class crypto{        map<string,crypto> map = new hashmap<string,crypto>();        private crypto(){        }        public static crypto getinstance(string key){           if(map.contains(key)){             return map.get(key);           }           else{             // switch on key , create cryptos             map.put(key,new crypto();           }           return map.get(key);        }     } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -