Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

値オブジェクト 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()); } }

Slide 8

Slide 8 text

値オブジェクト? 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; } }

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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