LoginSignup
15
8

More than 1 year has passed since last update.

DTOとは

  • オブジェクト指向プログラミングで用いられるデザインパターンの一つ
  • 関連するデータをまとめ、データの格納・読み出しのためのメソッドを定義したオブジェクト
  • データの受け渡し専用クラス
  • プログラム間でデータを効率良く、互いに利用しやすい形式で渡す手段

詳細

DTOにはビジネスロジックを含まない。
データを管理するためのフィールド変数と、
フィールド変数に対応したゲッター・セッターが定義されるのが一般的。

<?php

class HogeDto
{
  private string $id;
  private HogeValueObject $value;

  public function __construct(array $parameter)
  {
    $this->id = $parameter['id'];
    $this->value = $parameter['value'];
  }

  public function id(): string
  {
    return $this->id;
  }

  public function hogeValue(): HogeValueObject
  {
    return $this->value;
  }
}

参考

DTO(Data Transfer Object)とは - IT用語辞典 e-Words
DTO作るとき、パラメーター多すぎ問題どうしよう。【PHP】

15
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
8