public class ProductView {
private static ProductView instance = null;
private ProductView() {
}
public static ProductView getInstance() {
if (instance == null) {
instance = new ProductView();
}
return instance;
}
}
생성자를 private로 하여 외부에서 접근 불가능 하게 설정 한 후
instance가 비었을 경우에만 새로운 객체를 생성하게 함 -- 처음 한번의 객체만 생성하게 됨
'Java 기초 수업' 카테고리의 다른 글
<Java> builder 패턴 (0) | 2022.11.04 |
---|---|
https://refactoring.guru/ko/design-patterns/java (0) | 2022.11.04 |
<Java> static (0) | 2022.11.03 |
<Java> Entity Class, Service Class, required constructor (0) | 2022.11.03 |
<Java> 인터페이스 (0) | 2022.11.01 |