Recommended
PDF
GitHub Codespaces と Azure でつくる、エンタープライズレベルの開発環境
PPTX
PDF
アドテクを支える技術 〜1日40億リクエストを捌くには〜
PDF
UX/ユーザビリティのためのテスト - ユーザーテスト見学会 at JaSST
PDF
PPTX
Prelims, The Biz Short- Chakra View 2016
PDF
PDF
ODP
Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性
PPTX
PPT
PDF
The way to the timeless way of programming
PPT
Metaprogramming With Ruby
PDF
PDF
PDF
Design Pattern From Java To Ruby
PDF
【アシアル塾】PHPオブジェクト指向再入門・第四回デザインパターンに学ぶクラス設計
PDF
PPTX
PDF
PPT
PDF
Software Development with Symfony
PDF
Scrum alliance regional gathering tokyo 2013 pub
PDF
デザインパターンとともに学ぶオブジェクト指向のこころ
PDF
PDF
PDF
PDF
2019年度 若手技術者向け講座 デザインパターン
PDF
PDF
2019年度 若手技術者向け講座 オブジェクト指向
More Related Content
PDF
GitHub Codespaces と Azure でつくる、エンタープライズレベルの開発環境
PPTX
PDF
アドテクを支える技術 〜1日40億リクエストを捌くには〜
PDF
UX/ユーザビリティのためのテスト - ユーザーテスト見学会 at JaSST
PDF
PPTX
Prelims, The Biz Short- Chakra View 2016
PDF
PDF
Viewers also liked
ODP
Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性
PPTX
PPT
PDF
The way to the timeless way of programming
PPT
Metaprogramming With Ruby
PDF
PDF
PDF
Design Pattern From Java To Ruby
Similar to デザインパターン(初歩的な7パターン)
PDF
【アシアル塾】PHPオブジェクト指向再入門・第四回デザインパターンに学ぶクラス設計
PDF
PPTX
PDF
PPT
PDF
Software Development with Symfony
PDF
Scrum alliance regional gathering tokyo 2013 pub
PDF
デザインパターンとともに学ぶオブジェクト指向のこころ
PDF
PDF
PDF
PDF
2019年度 若手技術者向け講座 デザインパターン
PDF
PDF
2019年度 若手技術者向け講座 オブジェクト指向
PDF
PDF
DDD 20121106 SEA Forum November
PDF
Symfony2でより良いソフトウェアを作るために
PDF
PDF
PDF
文書をプログラムにする技術 - SimpleModeler + Mindmap & SmartDox
Recently uploaded
PDF
エンジニアが選ぶべきAIエディタ & Antigravity 活用例@ウェビナー「触ってみてどうだった?Google Antigravity 既存IDEと...
PDF
流行りに乗っかるClaris FileMaker 〜AI関連機能の紹介〜 by 合同会社イボルブ
PPTX
楽々ナレッジベース「楽ナレ」3種比較 - Dify / AWS S3 Vector / Google File Search Tool
PDF
20251210_MultiDevinForEnterprise on Devin 1st Anniv Meetup
PDF
Machine Tests Benchmark Suite. Explain github.com/alexziskind1/machine_tests #2
PDF
Machine Tests Benchmark Suite. Explain github.com/alexziskind1/machine_tests #1
デザインパターン(初歩的な7パターン) 1. 2. 3. 4. 5. 6. 7. 8. 9. class Singleton
{
//インスタンス保持用
private static $instance = null;
/**
* コンストラクタ
*/
private function __construct () {
}
/**
* インスタンス取得
*/
public static function get () {
if ( is_null ( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
}
$singleton = Singleton::get();
10. 11. 12. 13. $staffList = new StaffList();
$staffList->add("江口", 2);
$staffList->add("斎藤", 1);
foreach($staffList as $row){
var_dump($row->name, $row->sex);
}
string(6) "江口"
int(2)
string(6) "斎藤"
int(1)
class StaffList implements Iterator {
private $staffs = array();
private $index = 0;
//初期化
public function __construct () {
$this->index = 0;
}
//最初の要素に巻き戻す
function rewind () {
$this->index = 0;
}
//現在の要素を返す
function current() {
return $this->staffs[$this->index];
}
//現在の要素のキーを返す
function key () {
return $this->index;
}
//次の要素に進む
function next () {
$this->index++;
}
//現在位置が有効かどうかを調べる
function valid () {
return isset ( $this->staffs[$this->index] );
}
//追加
public function add ( $name, $sex ){
$staff = new Staff();
$staff->name = $name;
$staff->sex = $sex;
$this->staffs[$this->index] = $staff;
$this->index++;
}
}
14. 15. 16. 17. class ReaderFactory
{
/* Readerクラスのインスタンスを生成するAPI */
public function create ( $fileName )
{
$reader = $this->_createReader ( $fileName );
return $reader;
}
/** 生成するReaderサブクラスを選定する */
private function _createReader ( $fileName )
{
if (false !== stripos($fileName, '.xml')) {
return new XMLFileReader($fileName);
} else {
throw new Exception($fileName . ' is not supported.');
}
}
}
interface Reader
{
/** 読み込み */
public function read ();
/** 表示 */
public function display ();
}
class XMLFileReader implements Reader
{
/** コンストラクタ */
public function __construct($fileName)
{
if (!is_readable($fileName)) {
throw new Exception($fileName . 'is not readable.');
}
$this->_fileName = $fileName;
}
/** 読み込み */
public function read()
{
$this->_handler = simplexml_load_file($this->_fileName);
}
/** 表示 */
public function display()
{
foreach ( $this->_handler->channel->item as $item ) {
echo $item->title;
echo PHP_EOL;
}
}
}
Product
ConcreteProduct
Creator
18. 19. 20. 21. 22. 23. 継承の場合
interface Persion
{
public function getName();
}
class Employee
{
private $_name;
public function __construct( $name )
{
$this->_name = $name;
}
public function printName()
{
print($this->_name.PHP_EOL);
}
}
class EmployeePersion extends Employee implements Persion
{
public function __construct($name)
{
Employee::__construct($name);
}
public function getName (){
Employee::printName();
}
}
24. 25. 26. 委譲の場合
interface Persion
{
public function getName();
}
class Employee
{
private $_name;
public function __construct( $name )
{
$this->_name = $name;
}
public function printName()
{
print($this->_name.PHP_EOL);
}
}
class EmployeePersion implements Persion
{
private $_person;
public function __construct ( $name )
{
$this->_person = new Employee( $name );
}
public function getName (){
$this->_person->printName();
}
}
27. 28. 29. 30. 31. abstract class AbstractDisplay {
/** サブクラスに実装を任せる抽象メソッド **/
protected abstract function output ();
/** 抽象クラスで実装しているメソッド **/
final function display (){
$this->output();
}
}
/** サブクラスを実装 **/
class StringDisplay extends AbstractDisplay{
private $string;
function __construct($string){
$this->string = $string;
}
function output (){
echo $this->string."!".PHP_EOL;
}
}
$d = new StringDisplay("やったぜ");
$d->display();
やったぜ
32. 33. 34. 35. Implementor
class FileDataSource implements DataSource {
private $source_name;
private $handler;
function __construct($source_name) {
$this->source_name = $source_name;
}
function open() {
if (!is_readable($this->source_name)) {
throw new Exception('データソースが見つかりません');
}
$this->handler = fopen($this->source_name, 'r');
if (!$this->handler) {
throw new Exception('データソースのオープンに失敗しました');
}
}
function read() {
$buffer = array();
while (!feof($this->handler)) {
$buffer[] = fgets($this->handler);
}
return join($buffer);
}
function close() {
if (!is_null($this->handler)) {
fclose($this->handler);
}
}
}
ConcreteImplementor
class Listing {
private $data_source;
function __construct($data_source) {
$this->data_source = $data_source;
}
function open() {
$this->data_source->open();
}
function read() {
return $this->data_source->read();
}
function close() {
$this->data_source->close();
}
}
Abstraction
interface DataSource {
public function open();
public function read();
public function close();
}
Implementor
Implementor
class ExtendedListing extends Listing {
function __construct($data_source) {
parent::__construct($data_source);
}
function readWithEncode() {
return htmlspecialchars($this->read(), ENT_QUOTES);
}
}
RefinedAbstraction
aggrigate
36. apacheのアクセスログ
apacheのアクセスログ
$list1 = new Listing(new FileDataSource('access.log'));
$list2 = new ExtendedListing(new FileDataSource('access.log'));
try {
$list1->open();
$list2->open();
}
catch (Exception $e) {
die($e->getMessage());
}
$data = $list1->read();
echo $data.PHP_EOL;
$data = $list2->readWithEncode();
echo $data.PHP_EOL;
$list1->close();
$list2->close();
37. 38. 39. 40. //Strategy interface
interface Strategy {
public function test();
}
// Strategyインスタンスを実行するContext
class Context {
private function __construct(){}
public static function test( Strategy $strategy) {
return $strategy->test();
}
}
//Strategy interfaceの実装
class Test2 implements Strategy {
public function test() {
return 2;
}
}
//Strategy interfaceの実装
class Test1 implements Strategy {
public function test() {
return 1;
}
}
41. 42.