Views 11593 Votes 0 Comment 0
Atachment
Attachment '1'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

싱글톤 패턴 간단 예제

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) {
    }
}

?

List of Articles
No. Category Subject Author Date Views
629 Develop [ios] UIButton multi-line iOS7 hooni 2014.01.09 11433
628 Develop [ios] UIColor 지정에서 RGB define ㅎㅎ hooni 2013.04.23 22914
627 Develop [ios] UILabel top alignㅎㅎ hooni 2013.04.23 22840
626 Develop [ios] UITableView 특정 Row만 Update hooni 2014.04.08 4772
625 Develop [ios] UIView에서 상위 UIViewController 가져오기 hooni 2013.09.27 20150
624 Develop [ios] UIWebView 캐쉬 삭제 hooni 2014.04.08 3660
623 Develop [ios] UIWebView 쿠키 유지 hooni 2014.01.16 11704
622 Develop [ios] UIWebView를 이용한 로컬 HTML 파일 표시 file hooni 2015.01.02 1232
621 Develop [ios] UIWebView에서 NSURLRequest에 Cookie 실어 보내기 hooni 2014.01.16 14857
620 Develop [ios] UIWebView에서 로컬에 있는 html 파일 불러오기 hooni 2015.02.10 889
619 Develop [ios] UI컨트롤러 샘플코드 hooni 2013.08.08 15424
618 Develop [ios] URL Scheme 이용하여 앱 설치 확인 hooni 2014.03.10 4364
617 Develop [ios] URL 랜딩 속도(OpenURL 10초 정지되는) 이슈 hooni 2015.02.09 847
616 Develop [ios] URL 파라미터 파싱~ hooni 2014.05.12 3668
615 Develop [ios] Using protobuf(Protocol Buffers) on iPhone (iOS) file hooni 2014.03.20 4982
614 Develop [ios] UUID 생성 + Key Chain 연동 file hooni 2016.05.13 4657
Board Pagination Prev 1 ... 33 34 35 36 37 ... 74 Next
/ 74