Value Objectが盛り上がっているらしい。 Value Objectについて整理しよう - Software Transactional Memo Value Objectの説明に異論がないものの、主題はValue Object Obsessionのほうですよね。 こちらも聞いてみた。 fukabori.fm よい機会なので、よくわかっているつもりの、値オブジェクトというかドメイン固有型について再考してみよう。 それは値か属性か それはエンティティの全メンバーやデータベースの全列のために「顧客郵便番号」「送付先郵便番号」「事業所郵便番号」「契約日」などのクラス(メンバではなくクラス!)を定義して、immutableな振る舞いを強制する事を以てValue Objectであると言い張り、ドメイン知識の断片をそれぞれのクラスに書き散らして「高凝集になった」「型システムが守ってくれる」と喜
はじめに DDDの実装パターンとして、エンティティと値オブジェクトというものがあります。 ドメイン駆動一般に複雑な抽象論が多い中で、コードに近く一番イメージがつきやすいコード事例として出てくるため、ここだけは何となくわかるぞ!という方もいらっしゃるのではないでしょうか。 今日はこちらの概要とそれぞれの使い道について書きたいと思います。 先にざっくりイメージ図をお伝えすると、こういう図を使って解説します。 何の目的で作るのか? ドメイン駆動設計は何を解決しようとしているのか こちらの記事で、ドメイン駆動設計のアプローチは以下の2ステップがあるということを書きました。 ドメインの問題を解決するための抽象的なモデルを作る. モデルをソフトウェア(コード)に落とし込む ※ ドメイン=ソフトウェアを適用して問題解決しようとする領域 DDDでは、このStep2の モデルをコードで表現するためのパターン
本稿ではPHPで振る舞いを持つEnumの実装方法を順を追って説明していく。 Enumを定数で実装する方法も考えられるが、本稿ではクラスを使う。クラスでEnumを実装すると、それぞれの値に振る舞い(メソッド)を持たせられる利点がある。加えて、クラスで表現されたEnumはそれを利用するコードでクラス名を型宣言に使えるので、型安全なコードを書ける長所もある。 本稿では「支払い状況」を例にEnumを作っていく。まず、支払い状況は4つの状態があるものと考えよう。 保留(pending) 承認済み(approved) 却下(rejected) 支払い済み(paid) これらを実装していく過程を見ていこう。 なお、本稿で実装したコードはGitHubで公開しているので、完成版はそちらをご覧いただきたい。 まず、「支払い状況」のEnumクラスを作る。このクラスは継承する必要がないためfinalクラスにする。
現在、データベースのレコード単位で一意に識別されるデータを不変オブジェクトをベースにしたEntity Objectと、その属性となるValue Objectの設計を実践中ですが、やったこと&やっていることのメモです。 内容的には Traitで不変オブジェクトにしてキャッシュ可能なクラスを作る からの続きになります。 Entity Objectの利点 Entityではなく単なる連想配列として実装していた頃は、たとえば管理画面にログイン中のユーザーが一覧のうち自身の情報のみ編集できるとして、こんな感じで書いてました。(例はSmarty3 + Bootstrap2) 配列の場合 {{foreach $administrators as $administrator}} <tr> <td>{{$administrator.name}}</td> <td>{{$administrator.login
実践DDD本の第5章「エンティティ」 ~一意な識別子で同一性を識別~ 値オブジェクトとは DDDにおける「値オブジェクト」は何かを計測したり、定量化したりして説明する際に使用するオブジェクトです。数字/文字列/日付をはじめ、姓/名/金額/色といった「ユビキタス言語」を表現するために活用します。例えば、電話番号を数値型(Int型)ではなくPhoneNumber型を作ることで、ドメインの業務をプログラムでわかりやすく示すことができます。 5章で紹介した「エンティティ」とは対照的に「一意に識別して変更を管理する必要がないモノ」を値オブジェクトとします。適切に設計していれば、値を想定外に書き換えられてしまうリスクが無いため安心して開発できます。そのため、使いやすくテストしやすいメリットがあります。保守性や可読性に優れているため、DDDでは積極的に使用することが推奨されています。 値オブジェクトの特
この投稿は、PHP Advent Calendar 2016 - Qiita の 7 日目です。 DDD のようなドメインを意識した開発手法でなくても、ドメインコンテキストで必要な操作のみを実装したクラスを作ってみましょう話です。 Amazon Dash Button Amazon Dash Button は、ボタンが一つだけあるデバイスです。このボタンを押すと、あらかじめ決められた商品の注文が Amazon に送信され、商品が配送されるというシンプルなものです。 このデバイスは、「商品を届けて欲しい」というユースケースに対して、ボタンを押すというシンプルなインターフェイスを実装しています。単にボタンを押すだけなので、その裏側でどのようにして実現されているかを知らずとも、誰もが利用できます。違う言い方をすれば、ボタンを押す(商品を注文する)ことしかできないので、操作方法を覚える必要もなく、
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く