akkun_choi pedia
mindiaakkun_choi pedia見出し語

ドメインモデル

akkun_choi · 2009-03-12 更新

ドメインオブジェクト使うパターン

J2EE(よく知らない)やRuby on Railsに始まり、昨今のフレームワークはだいたいこのパターン

トランザクションスクリプトは処理をオブジェクトにするパターンドメインモデルは実際のもの(簡単にいえば1件のレコード)をオブジェクトにするパターン

>|php|
<?php
class PageStrategy{
protected $pdo;
protected $isPublicSql = 'select * from page where id = ?';
function isPublic($id){
$result = $this->pdo->query($this->isPublicSql, $id);
// .....some procedure
}
}
class Page{
protected $id;
protected $strategy;
function __construct($id, PageStrategy $strategy){
$this->id = $id;
$this->strategy = $strategy;
}
function isPublic(){
return $this->strategy->isPublic($this->id);
}
}

$page = new Page(new PageStrategy());
if ($page->isPublic()){
// ...
}
||<

関連する見出し語