Develop
2013.11.18 17:11
[java] 초간단 싱글톤(Singleton) 패턴 샘플 코드
조회 수 11621 댓글 0
첨부 '1' |
---|
싱글톤 패턴 간단 예제
import java.util.HashMap; class Singleton { private static HashMap map = new HashMap(); //private static Logger logger = Logger.getRootLogger(); protected Singleton() { // Exists only to thwart instantiation } public static synchronized Singleton getInstance(String classname) { Singleton singleton = (Singleton)map.get(classname); if(singleton != null) { System.out.println("got singleton from map: " + singleton); return singleton; } try { singleton = (Singleton)Class.forName(classname).newInstance(); } catch(ClassNotFoundException cnf) { System.out.println("Couldn't find class " + classname); } catch(InstantiationException ie) { System.out.println( "Couldn't instantiate an object of type " + classname); } catch(IllegalAccessException ia) { System.out.println("Couldn't access class " + classname); } map.put(classname, singleton); System.out.println("created singleton: " + singleton); return singleton; } } class SingletonTest { public static void main(String[] args) { } }
-
[ios] iOS 4.0 beta 에서 3.1.3으로 다운그레이드 하는 법
-
[ios] iOS 6.0 이상 회전 하기 (이전 버전과 비교 변경 부분)
-
[ios] iOS 7 이상 UIBarButtonItem 여백
-
[ios] iOS 8 개발자가 우선 알아야 할 3가지
-
[ios] iOS In App Purchase #1 (코드 구현 전 웹 설정 작업)
-
[ios] iOS In App Purchase #2 (코드 구현)
-
[ios] iOS In App Purchase 코드 부분 샘플 1
-
[ios] iOS In App Purchase 코드 부분 샘플 2
-
[ios] iOS 사운드 관련 프레임워크
-
[ios] iOS 앱 아이콘을 만드는 유틸
-
[ios] iOS 의 인앱구매 소개
-
[ios] iOS앱의 Xcode 빌드 과정