尤川豪   ·  3年前
445 貼文  ·  275 留言

我在 2015 年的時候寫信給 DHH 問過 domain modeling 的問題

突然想到我在 2015 年的時候寫信給 DHH 問過 domain modeling 的問題

他回信說:

...

I'm not a big fan of service objects in general and both query and policy objects are rarely something I reach for unless something is very complex and had its own state.

But having regular Ruby objects inside app/models is not just fine but encouraged.

...

The vast majority of my models are less than 100 lines. 1k+ line models is not good at all. Gotta split that up.

...

到了 2020 年我還是不太懂 所以他不使用 service objects

然後既然是 RoR 所以 active record based model 還是對應到資料表

不使用 service objects 然後每個 model 不到 100 行

然後他 app/models 底下很多類別是 plain old ruby object. 不是 active record based 類別.

所以這些 AR-based 與非 AR-based 的類別彼此是怎麼互動??

大概是把那些 AR-based models 當作 data structure 使用

然後不喜歡純行為的 service objects 類別

所以把相關的行為跟狀態放在一起建成比較漂亮的類別 這樣吧?

所以說起來 domain modeling 終究還是 OOP 基本功、design pattern 基本功的問題 對嗎?

  分享   共 1,228 次點閱
共有 0 則留言
還沒有人留言。歡迎分享您的觀點、或是疑問。
您的留言
尤川豪
445 貼文  ·  275 留言

Devs.tw 是讓工程師寫筆記、網誌的平台。隨手紀錄、寫作,方便日後搜尋!

歡迎您一起加入寫作與分享的行列!

查看所有文章