Upgrade to Pro — share decks privately, control downloads, hide ads and more …

値と属性の話

Akira Suenami
May 12, 2022
110

 値と属性の話

Akira Suenami

May 12, 2022
Tweet

More Decks by Akira Suenami

Transcript

  1. 値と属性
    2022/05/12 第1回なんでもわちゃわちゃLT会
    末並 晃 @a_suenami

    View Slide

  2. 自己紹介
    ● 末並 晃 @a_suenami
    ● 生息している界隈: DDDとか、TDDとか、RDBとか
    ● お仕事で使ってる技術スタック: Rails, React, Java
    ○ 最近は terraform おじさんです
    ● 好きな RDBMS: PostgreSQL
    ● 好きな制約: チェック制約
    ● 好きな焼肉の部位: ハラミ
    ● 好きな(ry

    View Slide

  3. インターネット上での立場

    View Slide

  4. インターネット上での立場
    ひたすら焼肉をタカられるという
    エンターテイメントをインターネットに提供し
    ています。
    (焼肉を奢るとは言ってない)

    View Slide

  5. 今日話すこと
    ● 「みんな、何でも値オブジェクトって言いすぎじゃない?」
    ● 値オブジェクトとは何か
    ● 属性とは区別しようねという話
    ● アランケイとリッチヒッキーの議論は興味深い

    View Slide

  6. View Slide

  7. 値オブジェクト
    enum Currency {
    JPY,
    USD
    }
    class Money {
    private Currency currency;
    private int amount;
    Money(final Currency currency, final int amount) {
    this.currency = currency;
    this.amount = amount;
    }
    Currency getCurrency() {
    return this.currency;
    }
    int getAmount() {
    return this.amount;
    }
    Money add(Money another) {
    if (this.currency != another.getCurrency()) {
    throw new IllegalArgumentException("通貨が異なります");
    }
    return new Money(this.currency, this.amount + another.getAmount());
    }
    }

    View Slide

  8. 値オブジェクト?
    class ProductUnitPrice {
    private Currency currency;
    private int amount;
    ProductUnitPrice(final Currency currency, final int amount) {
    this.currency = currency;
    this.amount = amount;
    }
    Currency getCurrency() {
    return this.currency;
    }
    int getAmount() {
    return this.amount;
    }
    }

    View Slide

  9. どうせこうなる
    ProductUnitPrice productUnitPrice = new ProductUnitPrice(Currency.JPY, 100);
    int quantity = 10;
    int totalPrice = productUnitPrice.getAmount() * quantity;

    View Slide

  10. 値と属性
    識別子(ID) 値
    属性

    View Slide

  11. アランケイとリッチヒッキー

    View Slide

  12. アランケイとリッチヒッキー
    https://news.ycombinator.com/item?id=11945722

    View Slide

  13. ご清聴ありがとうございました。

    View Slide