forked from sunday-develop/toby-spring
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
앞에서 상속으로인한 확장의 단점을 알아봤다. UserDao에서 Connection의 관심사를 새로운 클래스로 분리 & 확장해보자. (SimpleConnectionMaker) 하지만 단점 발생 1. UserDao는 DB 커넥션을 가져오는 구체적인 방법에 종속되어 있다. UserDao에 SimpleConnectionMaker인스턴스를 직접 사용하기 때문에, N사 D사로 구분하려면 문제가 발생한다. (즉, UserDao의 수정이 불가피해진다.) 2. 메소드명이 변경되어서는 안된다. 만약에 NUserDao에서 db 커넥션을 가져오는 메서드 이름을 openConnection으로 사용한다면, UserDao의 수 많은 메서드들이 변경되어야 한다.
- Loading branch information
1 parent
2589ebb
commit 7f5ae21
Showing
4 changed files
with
22 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/toby/tobyspring/user/dao/SimpleConnectionMaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.toby.tobyspring.user.dao; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
public class SimpleConnectionMaker { | ||
public Connection makeNewConnection() throws ClassNotFoundException, SQLException { | ||
Class.forName("oracle.jdbc.driver.OracleDriver"); | ||
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "dahye", "dahye"); | ||
return connection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters