1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ドメイン駆動設計の勉強_Entity

Posted at

はじめに

DDDについて値オブジェクトに続き、Entityについて書いていこうと思います。
Value Object(VO)とEntityを使うことで業務知識をクラスで表現することができます。実際の実装時には、これらのクラスを作っていき、ユースケースで活用していきます。

Entity

Entityは識別子を持ったオブジェクトで、現実世界を表現したものです。
例えば「商品」にはIDがあり、そのID(VO)が識別子となって他の商品と区別します。
Entityには以下の特徴があります。

可変

VOとはことなり、Entity内のプロパティは変更可能です。
商品の値段が変わった場合、商品内にある値段プロパティはオブジェクトを入れ替えます。
可変かどうかでEntityにするか、VOにするか判断してクラスを作成していきます。

同じ属性でも区別

Entityは識別子によって区別されます。
なので、同じプロパティを持っていても識別子が違えば別のものになります。
例えば商品名は同じだけど、IDが違う、などになります。

同一性で区別

識別子で区別するので、内部のプロパティや他の要素が変更されても影響はありません。

まとめ

今回はEntityについて書いていきました。
他にDDDにはRepositoryやServiceなどありますが、
主にVOとEntityを作っていくことで、業務知識を表現することができます。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?