Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76ce920

Browse files
committed
feat: Add practical real-world examples for Singleton, Builder, and Strategy patterns
Added comprehensive real-world examples with tests and documentation for threecommonly used design patterns in enterprise applications.## Singleton Pattern- ConfigurationManager: Application settings management- LoggerService: Centralized logging system- DatabaseConnectionPool: Connection pool management- Full test coverage for all implementations- Updated README with usage examples and Korean documentation## Builder Pattern- UserDTO: Complex user data transfer object- HttpRequest: HTTP request builder for API calls- EmailMessage: Email composition with attachments- Comprehensive tests for all builders- Enhanced README with practical use cases## Strategy Pattern- PaymentProcessor: Payment processing system- CreditCardPayment: Credit card payment strategy- BankTransferPayment: Bank transfer strategy- PayPalPayment: PayPal integration strategy- Complete test suite for payment strategies- Updated README with e-commerce payment exampleAll examples include:- Production-ready code with validation- Comprehensive JUnit 5 tests- Detailed Javadoc documentation- Korean and English README sections- Real-world use cases and best practices
1 parent751b3b9 commit76ce920

File tree

22 files changed

+4983
-1
lines changed

22 files changed

+4983
-1
lines changed

‎builder/README.md‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,111 @@ Use the Builder pattern when
129129
*[Apache Camel builders](https://github.com/apache/camel/tree/0e195428ee04531be27a0b659005e3aa8d159d23/camel-core/src/main/java/org/apache/camel/builder)
130130
*[Apache Commons Option.Builder](https://commons.apache.org/proper/commons-cli/apidocs/org/apache/commons/cli/Option.Builder.html)
131131

132+
##실무 예제 (Practical Examples)
133+
134+
###1. UserDTO - 사용자 정보 DTO
135+
136+
API 요청/응답에서 사용되는 복잡한 사용자 정보 객체를 Builder 패턴으로 구성합니다.
137+
138+
```java
139+
UserDTO user=UserDTO.builder()
140+
.id(1L)
141+
.username("john.doe")
142+
.email("john@example.com")
143+
.firstName("John")
144+
.lastName("Doe")
145+
.age(30)
146+
.phoneNumber("010-1234-5678")
147+
.address("123 Main St, Seoul")
148+
.addRole("USER")
149+
.addRole("ADMIN")
150+
.active(true)
151+
.build();
152+
153+
System.out.println(user.getFullName());// "John Doe"
154+
System.out.println(user.hasRole("ADMIN"));// true
155+
```
156+
157+
**실무 활용:**
158+
- API 요청/응답 DTO 생성
159+
- 데이터베이스 엔티티에서 DTO로 변환
160+
- 테스트 데이터 생성
161+
- 복잡한 사용자 프로필 구성
162+
163+
###2. HttpRequest - HTTP 요청 빌더
164+
165+
REST API 호출을 위한 HTTP 요청을 체계적으로 구성합니다.
166+
167+
```java
168+
HttpRequest request=HttpRequest.builder()
169+
.post()
170+
.url("https://api.example.com/users")
171+
.addHeader("Content-Type","application/json")
172+
.addHeader("Authorization","Bearer token123")
173+
.addQueryParam("page","1")
174+
.addQueryParam("size","10")
175+
.jsonBody("{\"name\":\"John Doe\"}")
176+
.timeout(5000)
177+
.build();
178+
179+
String response= request.execute();
180+
```
181+
182+
**실무 활용:**
183+
- REST API 클라이언트 구현
184+
- HTTP 라이브러리 래퍼
185+
- 마이크로서비스 간 통신
186+
- 테스트용 HTTP 요청 생성
187+
188+
###3. EmailMessage - 이메일 메시지 빌더
189+
190+
복잡한 이메일 메시지를 단계적으로 구성합니다.
191+
192+
```java
193+
EmailMessage email=EmailMessage.builder()
194+
.from("sender@example.com")
195+
.to("recipient@example.com")
196+
.addCc("manager@example.com")
197+
.addBcc("admin@example.com")
198+
.subject("Welcome to our service!")
199+
.body("<h1>Welcome!</h1><p>Thank you for joining us.</p>")
200+
.html(true)
201+
.priority(Priority.HIGH)
202+
.addAttachment("/path/to/document.pdf")
203+
.build();
204+
205+
boolean sent= email.send();
206+
System.out.println("Total recipients:"+ email.getTotalRecipientCount());
207+
```
208+
209+
**실무 활용:**
210+
- 이메일 발송 시스템
211+
- 알림 서비스
212+
- 마케팅 이메일 생성
213+
- 시스템 알림 메일
214+
215+
##Builder 패턴의 실무 장점
216+
217+
1.**가독성**: 복잡한 객체 생성 과정을 명확하게 표현
218+
2.**유연성**: 선택적 파라미터를 쉽게 처리
219+
3.**불변성**: Immutable 객체 생성으로 Thread-safe 보장
220+
4.**유효성 검증**: build() 메서드에서 일괄 유효성 검증
221+
5.**유지보수성**: 새로운 속성 추가가 용이
222+
223+
##테스트 실행
224+
225+
각 실무 예제에는 comprehensive한 테스트 코드가 포함되어 있습니다:
226+
227+
```bash
228+
# 모든 테스트 실행
229+
mvntest
230+
231+
# 특정 테스트만 실행
232+
mvntest -Dtest=UserDTOTest
233+
mvntest -Dtest=HttpRequestTest
234+
mvntest -Dtest=EmailMessageTest
235+
```
236+
132237
##Credits
133238

134239
*[Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp