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

45번째 줄: 45번째 줄:
<source lang='PHP'>
<source lang='PHP'>
class Employee {
class Employee {
   protected $row;   
   protected $id; 
  protected $name; 
  protected $birth;   
   function __contruct($row) {
   function __contruct($row) {
     $this->row = $row;
     $this->id = $row['id'];
    $this->name = $row['name'];
    $this->birth = $row['birth'];
   }
   }
}
}

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

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;
  }
}
Person person = personDao.readPerson(123);

4 구현 예시 2

class Employee {
  protected $id;  
  protected $name;  
  protected $birth;  
  function __contruct($row) {
    $this->id = $row['id'];
    $this->name = $row['name'];
    $this->birth = $row['birth'];
  }
}
class EmployeeDao {
  protected $dataSource = null;

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

5 같이 보기

6 주석

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

7 참고 자료

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