modularize 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) [6] “ “ ※ 太字強調は引用者によるもの 16
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. トランザクションスクリプト + テーブルデータゲートウェイ ドメインロジックは スクリプト内にべた書き 24
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 サービスレイヤー 25
つであるオンラインマーケティングが 活きる新規事業を展開し、その成功確率を高めたい B. 高速な仮説検証と SEO 関連の開発を両立させるため、開発生産性が 高く、かつ Core Web Vitals で自然と高スコアが取れる構造を作りたい C. B の実現にあたってエンジニアにかかる認知負荷をできるだけ下げたい 近年の流行を取り入れることを 第一とした技術選定ではない 60
2. 馬田隆明 "PMF に到るまでのステージ別指針集 ",URL: https://speakerdeck.com/tumada/pmf-nidao- rumadefalsesutezibie-zhi-zhen-ji↩ 3. "6. 1on1 in Public by texta.fm",URL: https://anchor.fm/textafm/episodes/6--1on1-in-Public-e1078pn↩ 4. "Common web application architectures",URL: https://docs.microsoft.com/en- us/dotnet/architecture/modern-web-apps-azure/common-web-application-architectures↩ 5. Frank Buschmann,Regine Meunier,Hans Rohnert,Peter Sommerlad,and Michael Stal (1996) Pattern- Oriented Software Architecture,Volume 1,A System of Patterns: Wiley.↩ 6. Martin Fowler "PresentationDomainDataLayering",URL: https://martinfowler.com/bliki/PresentationDomainDataLayering.html↩ 7. Martin Fowler (2002) Patterns of Enterprise Application Architecture: Addison-Wesley Professional.↩ 70
9. "Welcome to Rails",URL: https://github.com/rails/rails/blob/6-1-stable/README.md↩ 10. "Active Record – Object-relational mapping in Rails",URL: https://github.com/rails/rails/tree/6-1- stable/activerecord#label-Philosophy↩ 11. kawasima "イミュータブルデータモデル",URL: https://scrapbox.io/kawasima/イミュータブルデータモデル↩ 12. Yuichi Goto "Ruby on Rails の正体と向き合い方",URL: https://speakerdeck.com/yasaichi/what-is-ruby- on-rails-and-how-to-deal-with-it↩ 13. "Introducing Web Vitals: essential metrics for a healthy site",URL: https://blog.chromium.org/2020/05/introducing-web-vitals-essential-metrics.html↩ 14. "More time, tools, and details on the page experience update",URL: https://developers.google.com/search/blog/2021/04/more-details-page-experience↩ 71