an information-rich program is to separate it into three broad layers: presentation (UI), domain logic (aka business logic), and data access. So you often see web applications divided into . . . On the whole Ive found this to be an effective form of modularization for many applications and one that I regularly use and encourage. ― Martin Fowler (2015) [10] “ “ ※ 太字強調は引用者によるもの 13
true) def self.call(email:) unless URI::MailTo::EMAIL_REGEXP.match?(email) return Result.new(errors: ["Email is invalid"]) end values = { email: email, confirmation_token: SecureRandom.uuid } DB.transaction do id = DB[:newsletter_subscriptions].insert(values) EmailConfirmationMailer.deliver(values) Result.new(subscription_id: id) end rescue StandardError Result.new(errors: ["Something went wrong"]) end end A. トランザクションスクリプト + テーブルデータゲートウェイ ドメインロジックは スクリプト内にべた書き 22
unless URI::MailTo::EMAIL_REGEXP.match?(email) return Result.new(errors: ["Email is invalid"]) end subscription = NewsletterSubscription.new(email: email) subscription.set_confrimation_token NewsletterSubscription.transaction do subscription.save! EmailConfirmationMailer .deliver(subscription.slice(:email, :confirmation_token)) Result.new(subscription_id: subscription.id) end rescue StandardError Result.new(errors: ["Something went wrong"]) end end B. ドメインモデル + アクティブレコード with サービスレイヤー 23
more features on a Prisma level that help you express data-related business logic (e.g. extended validation rules) and (2) provide callbacks/hooks for you to make it easier to implement business logic . . . I strongly encourage you and everyone else to share your use cases and feature requests . . . as this helps us to prioritizing and designing upcoming features! ― Johannes Schickling (Founder of Prisma,2019) [20] “ “ ※ 太字強調は引用者によるもの 48
start super stupid simple and then you just pay as you go for the complexity that you use and no more.” [26] “I also agree that apps that don t want or need that [Webpack] shouldn t have to wrestle with something this complex.” [27] 53
Rails の Active Record が果たす役割は、アクティブレコードの採用、 バリデーションとコールバックの導入によって、ドメインレイヤー以下を モデルクラスだけで構築できるようにすることである Active Record や CoC、リソースベースのルーティングによってコードの 記述量を減らすことで、Rails はその高い開発生産性を実現している 57
領域を再定義する",URL: https://zenn.dev/mizchi/articles/c638f1b3b0cd239d3eea↩ 9. Frank Buschmann,Regine Meunier,Hans Rohnert,Peter Sommerlad,and Michael Stal (1996) Pattern- Oriented Software Architecture,Volume 1,A System of Patterns: Wiley.↩ 10. Martin Fowler "PresentationDomainDataLayering",URL: https://martinfowler.com/bliki/PresentationDomainDataLayering.html↩ 11. Martin Fowler (2002) Patterns of Enterprise Application Architecture: Addison-Wesley Professional.↩ 12. "Active Record – Object-relational mapping in Rails",URL: https://github.com/rails/rails/tree/6-1- stable/activerecord#label-Philosophy↩ 13. kawasima "イミュータブルデータモデル",URL: https://scrapbox.io/kawasima/イミュータブルデータモデル↩ 14. Jeffrey Jose "Timing for bringing page experience to Google Search",URL: https://developers.google.com/search/blog/2020/11/timing-for-page-experience↩ 62
the DHH Stack™ with David Heinemeier Hansson",URL: https://share.transistor.fm/s/336e93f9↩ 23. DHH on Twitter,January 14 2021,11:18 PM,URL: https://twitter.com/dhh/status/1349722504483500041↩ 24. DHH on Twitter,Dec 26 2020,7:26 PM,URL: https://twitter.com/dhh/status/1342778751575347200↩ 25. "WICG/import-maps: How to control the behavior of JavaScript imports",URL: https://github.com/WICG/import-maps↩ 26. "Full Stack Radio | 151: DHH – Building HEY with Hotwire",URL: https://share.transistor.fm/s/152b6067↩ 27. "Webpacker presents a more difficult OOB experience for JS Sprinkles than Sprockets did - A May Of WTFs - Ruby on Rails Discussions",URL: https://discuss.rubyonrails.org/t/webpacker-presents-a-more- difficult-oob-experience-for-js-sprinkles-than-sprockets-did/75345/31↩ 64