Skip to content

Commit 1c7aa72

Browse files
committed
.
1 parent b375919 commit 1c7aa72

File tree

11 files changed

+263
-105
lines changed

11 files changed

+263
-105
lines changed

abstract-document/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<groupId>com.iluwatar</groupId>
3333
<version>1.26.0-SNAPSHOT</version>
3434
</parent>
35-
<artifactId>abstract-document</artifactId>
35+
<artifactId>korean</artifactId>
3636
<dependencies>
3737
<dependency>
3838
<groupId>org.junit.jupiter</groupId>

korean/src/Translator.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3+
*
4+
* The MIT License
5+
* Copyright © 2014-2022 Ilkka Seppälä
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
public class Translator {
26+
27+
private TranslationService translationService;
28+
29+
public Translator(TranslationService translationService) {
30+
this.translationService = translationService;
31+
}
32+
33+
public String translateToGerman(String englishText) {
34+
return translationService.translate(englishText, "de");
35+
}
36+
}
37+
38+
// Hypothetical TranslationService interface
39+
interface TranslationService {
40+
String translate(String text, String targetLanguage);
41+
}

singleton/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ Then in order to use:
5050
```java
5151
var enumIvoryTower1 = EnumIvoryTower.INSTANCE;
5252
var enumIvoryTower2 = EnumIvoryTower.INSTANCE;
53-
LOGGER.info("enumIvoryTower1={}", enumIvoryTower1);
54-
LOGGER.info("enumIvoryTower2={}", enumIvoryTower2);
53+
5554
```
5655

5756
The console output

singleton/README_IN_KOREAN.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "자바에서 싱글턴 패턴: 글로벌 액세스 포인트 구현"
3+
shortTitle: 싱글턴
4+
description: "자바 애플리케이션에서 리소스의 효율적 사용과 쉬운 접근을 보장하는 싱글턴 패턴에 대해 알아보세요. 예제와 상세한 설명으로 싱글턴 패턴을 구현하는 방법을 제공합니다."
5+
category: Creational
6+
language: ko
7+
tag:
8+
- GoF (Gang of Four)
9+
- 인스턴스화
10+
- 지연 초기화
11+
- 리소스 관리
12+
---
13+
14+
## 다른 이름
15+
16+
* 단일 인스턴스
17+
18+
## 싱글턴 디자인 패턴의 의도
19+
20+
자바 클래스가 단일 인스턴스만 가지도록 보장하고, 이 싱글턴 인스턴스에 대한 글로벌 액세스 지점을 제공합니다.
21+
22+
## 싱글턴 패턴과 현실 세계의 예시
23+
24+
### 현실 세계의 예
25+
26+
> 현실 세계에서 싱글턴 패턴을 비유할 수 있는 사례는 정부가 발급하는 여권입니다. 한 나라에서 각 시민은 단 한 개의 유효한 여권만 발급받을 수 있습니다. 여권 발급 기관은 동일한 사람이 중복된 여권을 발급받지 못하도록 보장합니다. 시민이 여행할 때마다 이 단일 여권을 사용해야 하며, 이는 여행 자격을 나타내는 고유하고 글로벌하게 인정받는 식별자로 작동합니다. 이와 마찬가지로, 싱글턴 패턴은 자바 애플리케이션에서 효율적인 객체 관리를 보장합니다.
27+
28+
### 쉽게 설명하자면
29+
30+
> 특정 클래스의 객체가 하나만 생성되도록 보장합니다.
31+
32+
### 위키백과 설명
33+
34+
> 소프트웨어 엔지니어링에서 싱글턴 패턴은 클래스의 인스턴스화를 하나의 객체로 제한하는 소프트웨어 디자인 패턴입니다. 시스템 전체에서 동작을 조율해야 하는 경우 유용합니다.
35+
36+
## 자바에서 싱글턴 패턴의 프로그래밍 예제
37+
38+
**Joshua Bloch, Effective Java 2nd Edition, p.18**
39+
40+
> 단일 요소 열거형(enum) 타입이 싱글턴을 구현하는 가장 좋은 방법입니다.
41+
42+
```java
43+
public enum EnumIvoryTower {
44+
INSTANCE
45+
}
46+
사용하려면 다음과 같이 작성합니다:
47+
var enumIvoryTower1 = EnumIvoryTower.INSTANCE;
48+
var enumIvoryTower2 = EnumIvoryTower.INSTANCE;
49+
LOGGER.info("enumIvoryTower1={}", enumIvoryTower1);
50+
LOGGER.info("enumIvoryTower2={}", enumIvoryTower2);
51+
52+
콘솔 출력:
53+
enumIvoryTower1=com.iluwatar.singleton.EnumIvoryTower@1221555852
54+
enumIvoryTower2=com.iluwatar.singleton.EnumIvoryTower@1221555852
55+
56+
자바에서 싱글턴 패턴을 사용할 때
57+
다음과 같은 경우 싱글턴 패턴을 사용하세요:
58+
59+
클래스의 인스턴스가 정확히 하나만 있어야 하며, 잘 알려진 액세스 포인트에서 클라이언트가 이 인스턴스에 접근해야 할 때
60+
단일 인스턴스가 서브클래싱으로 확장 가능해야 하며, 클라이언트가 코드를 수정하지 않고 확장된 인스턴스를 사용할 수 있어야 할 때
61+
62+
자바에서 싱글턴 패턴의 현실 세계 응용 사례
63+
로깅 클래스
64+
애플리케이션 구성 클래스
65+
연결 풀(Connection Pool)
66+
파일 관리자
67+
java.lang.Runtime#getRuntime()
68+
java.awt.Desktop#getDesktop()
69+
java.lang.System#getSecurityManager()
70+
싱글턴 패턴의 장점과 단점
71+
장점:
72+
단일 인스턴스에 대한 제어된 접근 제공
73+
네임스페이스 오염 감소
74+
작업과 표현의 세분화 가능
75+
필요한 경우 여러 인스턴스를 허용
76+
클래스 작업보다 유연함
77+
단점:
78+
글로벌 상태로 인해 테스트가 어려움
79+
복잡한 수명 관리가 필요할 수 있음
80+
동기화 없이 사용할 경우 병렬 처리 환경에서 병목 현상을 초래할 수 있음
81+
관련 자바 디자인 패턴
82+
추상 팩토리(Abstract Factory): 클래스가 단일 인스턴스를 가지도록 보장할 때 사용
83+
팩토리 메서드(Factory Method): 싱글턴 패턴은 생성 로직을 캡슐화하는 팩토리 메서드를 사용하여 구현 가능
84+
프로토타입(Prototype): 인스턴스 생성을 피하고 고유 인스턴스를 관리하며 싱글턴과 함께 작동 가능
85+
참고 문헌 및 크레딧
86+
Design Patterns: Elements of Reusable Object-Oriented Software
87+
Effective Java
88+
Head First Design Patterns: Building Extensible and Maintainable Object-Oriented Software
89+
Java Design Patterns: A Hands-On Experience with Real-World Examples
90+
Refactoring to Patterns
91+
yaml
92+
Copy code
93+
94+
95+

singleton/pom.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
</parent>
3535
<artifactId>singleton</artifactId>
3636
<dependencies>
37-
<dependency>
38-
<groupId>org.junit.jupiter</groupId>
39-
<artifactId>junit-jupiter-engine</artifactId>
40-
<scope>test</scope>
41-
</dependency>
37+
<dependency>
38+
<groupId>org.junit.jupiter</groupId>
39+
<artifactId>junit-jupiter-engine</artifactId>
40+
<version>5.9.2</version>
41+
<scope>test</scope>
42+
</dependency>
43+
4244
</dependencies>
4345
<build>
4446
<plugins>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.iluwatar.singleton;
2+
3+
/**
4+
* 싱글턴 패턴.
5+
* 싱글턴 패턴은 클래스의 인스턴스가 하나만 존재하도록 보장하며,
6+
* 그 인스턴스에 대한 전역 접근 지점을 제공합니다.
7+
*/
8+
public class Singleton {
9+
10+
// Singleton 클래스의 유일한 인스턴스
11+
private static Singleton 인스턴스;
12+
13+
// 새로운 인스턴스 생성을 방지하기 위한 private 생성자
14+
private Singleton() {
15+
System.out.println("Singleton 인스턴스가 생성되었습니다.");
16+
}
17+
18+
/**
19+
* Singleton 클래스의 유일한 인스턴스를 가져오는 메서드.
20+
* 인스턴스가 아직 생성되지 않은 경우, 이 시점에서 생성됩니다.
21+
*
22+
* @return Singleton의 유일한 인스턴스.
23+
*/
24+
public static Singleton 가져오기() {
25+
if (인스턴스 == null) {
26+
인스턴스 = new Singleton();
27+
}
28+
return 인스턴스;
29+
}
30+
31+
/**
32+
* Singleton 인스턴스에서 호출 가능한 메서드 예제.
33+
*/
34+
public void 작업하기() {
35+
System.out.println("Singleton 인스턴스가 작동 중입니다.");
36+
}
37+
38+
// Singleton 패턴을 테스트하기 위한 메인 메서드
39+
public static void main(String[] args) {
40+
Singleton singleton = Singleton.가져오기();
41+
singleton.작업하기();
42+
}
43+
}
Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
1-
/*
2-
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3-
*
4-
* The MIT License
5-
* Copyright © 2014-2022 Ilkka Seppälä
6-
*
7-
* Permission is hereby granted, free of charge, to any person obtaining a copy
8-
* of this software and associated documentation files (the "Software"), to deal
9-
* in the Software without restriction, including without limitation the rights
10-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
* copies of the Software, and to permit persons to whom the Software is
12-
* furnished to do so, subject to the following conditions:
13-
*
14-
* The above copyright notice and this permission notice shall be included in
15-
* all copies or substantial portions of the Software.
16-
*
17-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23-
* THE SOFTWARE.
24-
*/
251
package com.iluwatar.singleton;
262

273
/**
28-
* BillPughImplementationTest
29-
*
4+
* Bill Pugh 싱글턴 구현 테스트 클래스.
305
*/
31-
public class BillPughImplementationTest
32-
extends SingletonTest<BillPughImplementation>{
33-
/**
34-
* Create a new singleton test instance using the given 'getInstance' method.
35-
*/
36-
public BillPughImplementationTest() {
37-
super(BillPughImplementation::getInstance);
38-
}
6+
public class BillPughImplementationTest extends SingletonTest<BillPughImplementation> {
7+
8+
/**
9+
* 주어진 'getInstance' 메서드를 사용하여 싱글턴 테스트 인스턴스를 생성합니다.
10+
*/
11+
public BillPughImplementationTest() {
12+
super(BillPughImplementation::getInstance);
13+
}
3914
}

0 commit comments

Comments
 (0)