KIDANI Akito
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- slideOptions: transition: slide --- # DDD輪読会 II-5 2022/05/26 [@kdnakt](https://twitter.com/kdnakt) --- ### 今日の範囲 - エリック・エヴァンスのドメイン駆動設計 - 5章 ソフトウェアで表現されたモデル - 関連 - エンティティ(ENTITIES) - 値オブジェクト(VALUE OBJECTS) - サービス(SERVICES) - モジュール(MODULES) - モデリングパラダイム --- ### 今日の概要 - 技術面でも概念面でも高凝集&疎結合がよい - オブジェクトの関連を設計して無駄をなくす --- ### 関連(Associations) - 現実の多対多、双方向の関連 - 実装と保守が複雑 ---- ##### 関連を扱いやすくする3つの方法 1. 関連をたどる方向を強制する 2. 限定子を付加して多重度を減らす 3. 本質的でない関連を除去する :::info 相互依存関係を減らしシンプルな設計に ::: ---- #### アメリカ大統領の例(1) - 国と大統領:双方向の関係性 ``` アメリカ(の大統領) -> ワシントン、ジェファーソン、モンロー ワシントン -> アメリカ(の大統領) ジェファーソン -> アメリカ(の大統領) モンロー -> アメリカ(の大統領) ``` ---- #### アメリカ大統領の例(2) 1. 関連をたどる方向を強制する ``` アメリカ(の大統領) -> ワシントン、ジェファーソン、モンロー ``` 2. 限定子を付加して多重度を減らす ``` 1790年のアメリカ(の大統領) -> ワシントン ``` --- ### エンティティ(ENTITIES) - 同一性identityで定義されるオブジェクト - 属性によって定義されるのではない - 属性は変化する - 同じ属性を持つケースも (例:同姓同名) - 要はアプリのユーザが気にするかどうか ---- ##### オブジェクト指向言語における同一性 - 同一性の演算:Javaの==演算子など - メモリ上の位置の比較など - ドメインではほぼ無意味 - 例)同日同口座同額の預入 - 別の一意の識別子が必要 - 同じモノでもモデル上の表現が変わる - 例)座席予約:自由席と指定席 ---- ##### エンティティをモデル化する - 同一性の定義:ドメイン理解が必要 - パターン1:オブジェクトの属性 - 例)新聞:名前、都市、発行日 - パターン2:属性でキーが決まらない - UUIDなど自動生成 - ID表示すべきか問題(ドメイン次第) - パターン3:システム境界を越える同一性 - マイナンバー、社会保障番号etc - 同一性の最終判断はユーザが行う --- ### 値オブジェクト(VALUE OBJECTS) - ドメインにおける記述的な側面を表現する - 概念的な同一性を持たない - 複雑な値オブジェクト - 値オブジェクトから構成される - エンティティを参照する ---- ##### 住所:エンティティか値オブジェクトか? - 通販ドメインの顧客の住所:値オブジェクト - 郵便ドメインの住所:エンティティ - 電気会社のドメイン - サービス提供先:エンティティ - 住居の一属性:値オブジェクト ---- ##### 値オブジェクトの凝集度 - 概念的にまとまりとして表現すべき ``` // NG 顧客: { 名前, 都道府県, 市区町村, 番地 } // OK 顧客 { 名前, 住所 { 都道府県, 市区町村, 番地 } } ``` ---- ##### 値オブジェクトの設計 - 同一性がない=どのインスタンスでも良い - 設計が自由、性能最適化が可能 - 別のエンティティにコピーできる - 別のエンティティと共有できる - ゆえに不変であるべし - 性能のため1インスタンスを共有 ```java= // JavaのLong.javaの例 public static Long valueOf(long l) { final int offset = 128; if (l >= -128 && l <= 127) { // will cache return LongCache.cache[(int)l + offset]; } return new Long(l); } ``` ---- ##### 値オブジェクトに可変性を認めるべきか? - パフォーマンスを考慮して許可するケースも - 値が頻繁に変化する - オブジェクト生成・削除が高コスト - クラスタリングが妨げられる場合 :::warning クラスタリングのくだりよく分からなかった🙇‍♂️ ::: ---- ##### 値オブジェクトを含む関連を設計する - モデル中の関連は数が少なく単純である方が良い - 双方向の関連 - エンティティの場合、保守が困難に - 値オブジェクトの場合、役に立たない(同一性がないので) --- ### サービス(SERVICES) - どのオブジェクトにも属さない操作の集合 - 手続き型プログラミングはNG - エンティティ/値オブジェクトから 全ふるまいを奪うのもNG ---- ##### 優れたサービスの3つの特徴 - 操作がドメインの概念に関係している - ドメインモデルに基づくインターフェース定義 - 操作に状態がない(副作用はあってもよい) ---- ##### サービスと隔離されたドメイン層 - サービスの3つのレイヤ - インフラ層の技術的サービス - アプリケーションサービス - ドメインサービス - インフラ層の技術的サービス - 例)メール通知サービス - ビジネスに関する意味が一切ないはず - アプリケーションサービス - ドメイン/技術的サービスを呼び出す - 入力を変換する - ドメインサービス - 例)銀行業ドメインの資金振替サービス ---- ##### 粒度 - アプリケーションサービス:ドメインオブジェクトのふるまいが組み合わさる場所 - ドメインサービスの粒度が細かいと、 ドメイン知識がここに流出する - 中くらいの粒度のサービスが吉 :::danger 中くらいってなんやねん! (現時点では説明なし) ::: --- ### モジュール(MODULES) - パッケージ(PACKAGES)ともいう - 認知負荷を下げるためにモジュール化 - モジュールの内部詳細に専念(高凝集) - モジュール間の関係性に着目(疎結合) - ドメイン層のモジュール - 意味のあるモデルの一部 - コードだけでなく概念も分割 ---- ##### アジャイルモジュール - 初期の誤ったモジュールが利用されがち - オブジェクトの結合度が高い - リファクタリングが困難 - ドメイン理解の深化に合わせ モジュールも変化すべき - 広範囲のコード変更、混乱を生む可能性 - 歯を食いしばってリファクタリング(モジュール再構成)すべき ---- ##### Javaのパッケージ利用例 - `import my.package.*` - モジュールの依存関係を伝える - リファクタリングが楽 :::info あまり推奨されない (参考:[フューチャー株式会社の規約](https://future-architect.github.io/coding-standards/documents/forJava/Java%E3%82%B3%E3%83%BC%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0%E8%A6%8F%E7%B4%84.html#%E3%82%A4%E3%83%B3%E3%83%9B%E3%82%9A%E3%83%BC%E3%83%88)) ::: ---- ##### フレームワーク駆動パッケージングの代償 - 例:J2EEの分割規約 - オブジェクトが散らばってしまう - 複雑なフレームワークの理解で疲弊 - ドメインコードとそれ以外を分離するために パッケージを利用せよ - 参考:第4部 戦略的設計 --- ### モデリングパラダイム - モデル駆動設計=オブジェクト指向設計だけ、ではない - オブジェクト指向設計はシンプルだがドメイン知識を伝える力がある - 高度に数学的なドメインなどは不適 - ルールエンジンやワークフローなどのパラダイムもある - 斬新なパラダイムはそれを使える開発者やツールが少ない問題 ---- ##### パラダイムの混在 - 基本的にパラダイムを混在させないよう 努力すべき - どの実装でも使える 単一のモデルを見つけよう - 複数のパラダイムをまとめる効果的なツール =ユビキタス言語 --- ### まとめ - ドメインオブジェクト:エンティティ、 関連、値オブジェクト、サービス、モジュール - 実装とモデルが直接一致する場所 - ドメインオブジェクトが実現するモデルと 関係ないものを追加してはいけない - 技術的なオブジェクトについては第6章

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully