"데이터 접근 객체"의 두 판 사이의 차이

17번째 줄: 17번째 줄:
http://www.oracle.com/ocom/groups/public/@otn/documents/digitalasset/145996.jpg
http://www.oracle.com/ocom/groups/public/@otn/documents/digitalasset/145996.jpg


==코드 예시 (PHP)==
==구현 예시 1 ==
<source lang='PHP'>
<source lang='java'>
class Employee {
public class Person {
   // ... (생략)
  ... (생략)
}
 
public class PersonDao {
  protected DataSource dataSource = null;
 
  public PersonDao(DataSource dataSource){
    this.dataSource = dataSource;
   }
 
  public Person readPerson(long personId){
    Connection connection = this.dataSource.getConnection();
    Person person = ... (생략)
    return person;
  }
}
}
</source>


==구현 예시 2 ==
<source lang='PHP'>
class EmployeeDao {
class EmployeeDao {
   protected $dataSource = null;
   protected $dataSource = null;
31번째 줄: 48번째 줄:
   function readEmployee($employeeId) {
   function readEmployee($employeeId) {
     $connection = $this->dataSource->getConnection();
     $connection = $this->dataSource->getConnection();
     $row = $connection->query_row("SELECT * FROM employee WHERE id=?", $employeeId);
     return $connection->query_row("SELECT * FROM employee WHERE id=?", $employeeId);
    return new Employee($row);
   }
   }
}
}

2015년 1월 13일 (화) 14:39 판

1 개요

data access object; DAO
데이터 접근 객체, 데이터 액세스 개체

2 그림 예시

패턴 구조[4]

 

객체간 상호작용[5]

 

3 구현 예시 1

public class Person {
  ... (생략)
}

public class PersonDao {
  protected DataSource dataSource = null;

  public PersonDao(DataSource dataSource){
    this.dataSource = dataSource;
  }

  public Person readPerson(long personId){
    Connection connection = this.dataSource.getConnection();
    Person person = ... (생략)
    return person;
  }
}

4 구현 예시 2

class EmployeeDao {
  protected $dataSource = null;

  function __construct(DataSource $dataSource) {
    $this->dataSource = $dataSource;
  }
  function readEmployee($employeeId) {
    $connection = $this->dataSource->getConnection();
    return $connection->query_row("SELECT * FROM employee WHERE id=?", $employeeId);
  }
}

5 같이 보기

6 주석

  1. 주로 DB
  2. 데이터베이스 또는 파일시스템
  3. J2EE 패턴에서는 통합 티어
  4. 클래스 다이어그램
  5. 시퀀스 다이어그램

7 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}