← Back to list

*Singleton Pattern

- 실행 중인 JVM에서 단 하나의 객체만 만들고 사용하는 design pattern.

김르르 · 2021-04-08 08:05 · 0 claps · 1.4 min read
#statement #singleton #resultset #prepared-statements #singleton-pattern
Open on Medium ↗

*Singleton Pattern

  • 실행 중인 JVM에서 단 하나의 객체만 만들고 사용하는 design pattern.

  • 참조하는 속도가 빠르다.

  • 메모리를 절약할 수 있다.

  • 객체가 소멸되면, 다시 객체를 생성하도록 코딩하면 된다.

작성법)

public class Test{

private static Test test;

  1. 클래스외부에서 직접 객체화 할 수 없도록 만든다. (생성자의 접근지정자를 private으로)

private Test(){

}

  1. 클래스외부에서 생성된 객체를 얻을 수 있는 method를 작성

public static Test getInstance(){

// 객체를 하나로 유지하여

if( test == null){

test=new Test();

}

//객체를 반환하다.

return test;

}


메타데이터
post_id
12cd45f3c8f5
slug
singleton-pattern-12cd45f3c8f5
url
https://medium.com/@lleurxx/singleton-pattern-12cd45f3c8f5
canonical_url
https://medium.com/@lleurxx/singleton-pattern-12cd45f3c8f5
author_url
https://medium.com/@lleurxx
status
ok
fetched_at
2026-08-23 02:52:22