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.
- DB 커넥션에 대한 확장성을 고려하여 상속을 통해 분리해보자 두가지 디자인 패턴이 포함된다. 1. 템플릿 메소드 패턴 - 추상 메소드를 만들어 서브클래스에서 필요에 맞게 구현해서 사용할 수 있도록 구현하는 방법 :: UserDao 에서 getConnection 메서드 2. 팩토리 메소드 패턴 - 객체를 만들어내는 부분을 서브클래스에 위임 시킴 - NUserDao 와 DUserDao 에서 return 되는 각각의 Connection 또한, 단점이 포함된다. 1. 다중상속의 문제 2. 슈퍼클래스 내부의 변경이 있을 때, 모든 서브클래스에서 변경 사항이 생길 수 있다. 3. 해당 DB 커넥션을 생성하는 코드를 다른 dao 클래스에 적용할 수 없다.
- Loading branch information
1 parent
b30ba4a
commit 2589ebb
Showing
3 changed files
with
32 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.toby.tobyspring.user.dao; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
public class DUserDao extends UserDao { | ||
@Override | ||
public Connection getConnection() throws ClassNotFoundException, SQLException { | ||
// D사 db connection | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.toby.tobyspring.user.dao; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
public class NUserDao extends UserDao { | ||
@Override | ||
public Connection getConnection() throws ClassNotFoundException, SQLException { | ||
// N사의 DB 연결 | ||
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